读取pkcs12证书信息 [英] Reading pkcs12 certificate information
本文介绍了读取pkcs12证书信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在读取证书信息时遇到问题。我想使用Java和Android中的bouncycastle库来阅读完整信息。现在,我只是在控制台中使用keytool命令:
I have a problem with reading certificate information. I want to read full information using java with bouncycastle library in Android programmatically. Now, i'm just using keytool command in console:
>keytool -list -keystore 1.p12 -storetype pkcs12 -v
有任何建议吗?
推荐答案
我找到了解决方案,主要思想是将证书转换为x509,然后获取SubjectDN和解析值。
I've found solution, the main idea is to cast certificate to x509, then get the SubjectDN and parse values.
public class TestClass {
public static void main(String[] args) throws Exception {
KeyStore p12 = KeyStore.getInstance("pkcs12");
p12.load(new FileInputStream("pkcs.p12"), "password".toCharArray());
Enumeration<String> e = p12.aliases();
while (e.hasMoreElements()) {
String alias = e.nextElement();
X509Certificate c = (X509Certificate) p12.getCertificate(alias);
Principal subject = c.getSubjectDN();
String subjectArray[] = subject.toString().split(",");
for (String s : subjectArray) {
String[] str = s.trim().split("=");
String key = str[0];
String value = str[1];
System.out.println(key + " - " + value);
}
}
}
}
这篇关于读取pkcs12证书信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文