I want to extract information about RSA Public Key from the pfx file using java.
我有一个pfx文件并转换为x509 Pem文件 . 从pem文件,在终端中使用以下命令:
openssl x509 -in file.pem -text
我能够查看公钥指数和模数值
主题公钥信息:
Public Key Algorithm: rsaEncryption
Public-Key: (2048 bit)
Modulus:
00:da:7c:e0:3e:c4:62:8d:ce:29:04:2f:93:78:7c:
:
6a:e7:c9:7c:8b:6f:09:5c:75:5f:8c:5e:9c:6a:b9:
7:32:90: a4:4b
Exponent: 65537 (0x10001)
如何在java中提取以上信息?
Input: pfxfile和密码
Output :公钥指数和模数值 .
我使用下面的代码来提取公钥指数和模数,但我没有得到使用openssl提取的值 . 我怀疑java.security.cert.Certificate是否使用了其他一些DER格式?
什么是java等价的openssl?
Code:
KeyStore ks = KeyStore.getInstance("pkcs12");
ks.load(new FileInputStream(file), password.toCharArray());
Enumeration enumeration = ks.aliases();
while (enumeration.hasMoreElements()) {
String alias = (String) enumeration.nextElement();
java.security.cert.Certificate certificate = ks.getCertificate(alias);
PublicKey publickey = certificate.getPublicKey();
}
1 回答
您需要向下转换为透明的
java.security.interfaces.RSAPublicKey
类型 . 然后,您可以访问模数和公共指数 .