gpt4 book ai didi

java - 是否可以从私钥的 byte[] 数组中恢复 RSA 公钥?

转载 作者:行者123 更新时间:2023-11-30 04:59:27 41 4
gpt4 key购买 nike

我想知道是否可以从私钥恢复 RSA 公钥?私钥加载如下:

PrivateKey privateKey = GnuRSAPrivateKey.valueOf(Utils.hexStringToBytes(prvKey));

如何从私有(private)中加载公钥? privateKey.getFormat 返回 null。

最佳答案

我假设您的 GnuRSAPrivateKey 来自 the GNU Crypto project .

GnuRSAPrivateKey 实例包含私钥,以及一些额外的值,这些值并不是实现 RSA 严格需要的,但对于性能(使用中国剩余定理)和安全性(公共(public)指数对于掩蔽很有用,这有助于防止定时攻击)。因此,这个私钥也包含了公钥。

所以这应该有效:

GnuRSAPrivateKey sk = GnuRSAPrivateKey.valueOf(theEncodedPrivateKey);
PrivateKey privateKey = sk;
PublicKey publicKey = new GnuRSAPublicKey(sk.getN(), sk.getE());

关于java - 是否可以从私钥的 byte[] 数组中恢复 RSA 公钥?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7412015/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com