1. java怎麼讀取IE里證書信息
X509Certificate[] certs = (X509Certificate[]) req.getAttribute("javax.servlet.request.X509Certificate");
byte] certTrans = new byte[]{};
if (certs!= null && certs.length != 0) {
try {
certTrans = certs[0].getEncoded();
//輸出certTrans
}
2. java如何解讀證書里的內容(通過string 來生成X509Certificate對象)
那個字元串是Base64編碼後的
試著把String 轉成inputStream,
InputStream inStream = new ByteArrayInputStream(caString.getBytes('UTF-8'));用這句替代 上面寫的第二行代碼。但是在執行第四行的時候報錯。。
java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Unsupported encoding
3. java 如何讀取後綴為der證書中的內容,字元串顯示
der證書的內容都是加密過的,讀出來也是一串看不懂的字元串。讀取方式用java一般的file操作即可
4. 如何編一個Java應用讀取XP數字證書庫中的cer證書中的信息
這么復雜,還沒有分兒。。。幫你頂。關於開發就幫不上你了。
5. java怎麼去獲取證書文件的信息
Java為安全應用提供了豐富的API,J2SDK1.4 的JSSE (JavaTM Secure Socket Extension) 包括javax.security.certificate包,並且提供對證書的操作方法,代碼如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.table.*;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.io.*;
public class CARead extends JPanel {
private String CA_Name;
private String CA_ItemData[][] = new String[9][2];
private String[] columnNames = {"證書欄位標記","內容" };
public CARead(String CertName) {
CA_Name=CertName;
/* 三個Panel用來顯示證書內容*/
JTabbedPane tabbedPane = new JTabbedPane();
JPanel panelNormal = new JPanel();
tabbedPane.addTab("普通信息", panelNormal);
JPanel panelAll=new JPanel();
panelAll.setLayout(new BorderLayout());
tabbedPane.addTab("所有信息",panelAll);
JPanel panelBase64=new JPanel();
panelBase64.setLayout(new BorderLayout());
tabbedPane.addTab("Base64編碼信息",panelBase64);
/* 讀取證書常規信息 */
Read_Normal(panelNormal);
/* 讀取證書文件字元串表示內容 */
Read_Bin(panelAll);
/* 讀取證原始Base64編碼形式的證書文件 */
Read_Raw(panelBase64);
tabbedPane.setSelectedIndex(0);
setLayout(new GridLayout(1, 1));
add(tabbedPane);
}
}
定義證書信息的讀取函數如下:
private int Read_Normal(JPanel panel){
String Field;
try{
CertificateFactory certificate_factory=CertificateFactory.getInstance("X.509");
FileInputStream file_inputstream=new FileInputStream(CA_Name);
X509Certificate
x509certificate=(X509Certificate)certificate_factory.generateCertificate
(file_inputstream);
Field=x509certificate.getType();
CA_ItemData[0][0]="類型";
CA_ItemData[0][1]=Field;
Field=Integer.toString(x509certificate.getVersion());
CA_ItemData[1][0]="版本";
CA_ItemData[1][1]=Field;
Field=x509certificate.getSubjectDN().getName();
CA_ItemData[2][0]="標題";
CA_ItemData[2][1]=Field;
/* 以下類似,這里省略
Field=x509certificate.getNotBefore().toString();得到開始有效日期
Field=x509certificate. getNotAfter().toString();得到截止日期
Field=x509certificate.getSerialNumber().toString(16);得到序列號
Field=x509certificate.getIssuerDN().getName();得到發行者名
Field=x509certificate.getSigAlgName();得到簽名演算法
Field=x509certificate.getPublicKey().getAlgorithm();得到公鑰演算法 */
file_inputstream.close();
final JTable table = new JTable(CA_ItemData, columnNames);
TableColumn tc=null;
tc = table.getColumnModel().getColumn(1);
tc.setPreferredWidth(600);
panel.add(table);
}catch(Exception exception){
exception.printStackTrace();
return -1;
}
return 0;
}
6. java怎麼調用瀏覽器插件讀取系統內ca證書信息
tomcat可以讀證書,做CAS時用過,看是不是你想要的
7. 如何用Java讀取使用證書
Java為安全應用提供了豐富的API,J2SDK1.4 的JSSE (JavaTM Secure Socket Extension) 包括javax.security.certificate包,並且提供對證書的操作方法,代碼如下:
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.table.*;
importjava.security.cert.CertificateFactory;
importjava.security.cert.X509Certificate;
importjava.io.*;
{
privateStringCA_Name;
privateStringCA_ItemData[][]=newString[9][2];
privateString[]columnNames={"證書欄位標記","內容"};
publicCARead(StringCertName){
CA_Name=CertName;
/*三個Panel用來顯示證書內容*/
JTabbedPanetabbedPane=newJTabbedPane();
JPanelpanelNormal=newJPanel();
tabbedPane.addTab("普通信息",panelNormal);
JPanelpanelAll=newJPanel();
panelAll.setLayout(newBorderLayout());
tabbedPane.addTab("所有信息",panelAll);
JPanelpanelBase64=newJPanel();
panelBase64.setLayout(newBorderLayout());
tabbedPane.addTab("Base64編碼信息",panelBase64);
/*讀取證書常規信息*/
Read_Normal(panelNormal);
/*讀取證書文件字元串表示內容*/
Read_Bin(panelAll);
/*讀取證原始Base64編碼形式的證書文件*/
Read_Raw(panelBase64);
tabbedPane.setSelectedIndex(0);
setLayout(newGridLayout(1,1));
add(tabbedPane);
}
}
定義證書信息的讀取函數如下:
privateintRead_Normal(JPanelpanel){
StringField;
try{
CertificateFactorycertificate_factory=CertificateFactory.getInstance("X.509");
FileInputStreamfile_inputstream=newFileInputStream(CA_Name);
X509Certificate
x509certificate=(X509Certificate)certificate_factory.generateCertificate
(file_inputstream);
Field=x509certificate.getType();
CA_ItemData[0][0]="類型";
CA_ItemData[0][1]=Field;
Field=Integer.toString(x509certificate.getVersion());
CA_ItemData[1][0]="版本";
CA_ItemData[1][1]=Field;
Field=x509certificate.getSubjectDN().getName();
CA_ItemData[2][0]="標題";
CA_ItemData[2][1]=Field;
/*以下類似,這里省略
Field=x509certificate.getNotBefore().toString();得到開始有效日期
Field=x509certificate.getNotAfter().toString();得到截止日期
Field=x509certificate.getSerialNumber().toString(16);得到序列號
Field=x509certificate.getIssuerDN().getName();得到發行者名
Field=x509certificate.getSigAlgName();得到簽名演算法
Field=x509certificate.getPublicKey().getAlgorithm();得到公鑰演算法*/
file_inputstream.close();
finalJTabletable=newJTable(CA_ItemData,columnNames);
TableColumntc=null;
tc=table.getColumnModel().getColumn(1);
tc.setPreferredWidth(600);
panel.add(table);
}catch(Exceptionexception){
exception.printStackTrace();
return-1;
}
return0;
}
8. 為什麼用java讀取的證書DN信息亂碼
java文件讀取的時候有中文就很出現亂碼,通常獲取到的文件中通常都是「iso8859-1」格式,需要轉換為「UTF-8」格式。
如:String str = new String(str.getByte("iso8859-1"),"UTF-8");進行下強制轉換後在進行讀取即可。
備註:通常格式有GBK、UTf-8、iso8859-1、GB2312,如果上面的強制轉換不成功,依次進行這些格式的嘗試,肯定是可以解決問題的。
9. java如何解讀證書里的內容(通過string 來生成X509Certificate對象)
那個字元串是Base64編碼後的
試著把String 轉成inputStream,
InputStream inStream = new ByteArrayInputStream(caString.getBytes('UTF-8'));用這句替代 上面寫的第二行代碼。但是在執行版第四行的權時候報錯。。
java.security.cert.CertificateException: Could not parse certificate: java.io.IOException: Unsupported encoding
10. Java如何讀取PFX密鑰文件
package com.Jinhill;
import java.io.*;
import java.util.*;
import java.security.*;
import java.security.cert.Certificate;
public class ReadPFX {
public ReadPFX (){
}
//轉換成十六進制字元串
public static String Byte2String(byte[] b) {
String hs="";
String stmp="";
for (int n=0;n<b.length;n++) {
stmp=(java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length()==1) hs=hs+"0"+stmp;
else hs=hs+stmp;
//if (n<b.length-1) hs=hs+":";
}
return hs.toUpperCase();
}
public static byte[] StringToByte(int number) {
int temp = number;
byte[] b=new byte[4];
for (int i=b.length-1;i>-1;i--){
b[i] = new Integer(temp&0xff).byteValue();//將最高位保存在最低位
temp = temp >> 8; //向右移8位
}
return b;
}
private PrivateKey GetPvkformPfx(String strPfx, String strPassword){
try {
KeyStore ks = KeyStore.getInstance("PKCS12");
FileInputStream fis = new FileInputStream(strPfx);
// If the keystore password is empty(""), then we have to set
// to null, otherwise it won't work!!!
char[] nPassword = null;
if ((strPassword == null) || strPassword.trim().equals("")){
nPassword = null;
}
else
{
nPassword = strPassword.toCharArray();
}
ks.load(fis, nPassword);
fis.close();
System.out.println("keystore type=" + ks.getType());
// Now we loop all the aliases, we need the alias to get keys.
// It seems that this value is the "Friendly name" field in the
// detals tab <-- Certificate window <-- view <-- Certificate
// Button <-- Content tab <-- Internet Options <-- Tools menu
// In MS IE 6.
Enumeration enumas = ks.aliases();
String keyAlias = null;
if (enumas.hasMoreElements())// we are readin just one certificate.
{
keyAlias = (String)enumas.nextElement();
System.out.println("alias=[" + keyAlias + "]");
}
// Now once we know the alias, we could get the keys.
System.out.println("is key entry=" + ks.isKeyEntry(keyAlias));
PrivateKey prikey = (PrivateKey) ks.getKey(keyAlias, nPassword);
Certificate cert = ks.getCertificate(keyAlias);
PublicKey pubkey = cert.getPublicKey();
System.out.println("cert class = " + cert.getClass().getName());
System.out.println("cert = " + cert);
System.out.println("public key = " + pubkey);
System.out.println("private key = " + prikey);
return prikey;
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}
}