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;
}
}