我想使用 java 从 pfx 文件中提取有关 RSA 公钥的信息。
我有一个 pfx 文件并转换为 x509 Pem 文件。从 pem 文件,在终端中使用以下命令:
openssl x509 -in file.pem -text
Run Code Online (Sandbox Code Playgroud)
我可以查看公钥指数和模数值
主题公钥信息:
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)
Run Code Online (Sandbox Code Playgroud)
java中如何提取上述信息?
输入: pfxfile 和密码
输出:公钥指数和模数值。
我使用下面的代码来提取公钥指数和模数,但我没有得到使用 openssl 提取的值。我怀疑 java.security.cert.Certificate 是否使用其他 DER 格式??
什么是openssl的java等价物?
代码:
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(); …Run Code Online (Sandbox Code Playgroud)