java pem rsa_如何从java中的pfx文件/ pem文件中获取RSA公钥的指数和模数值

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();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值