开发者

Is it possible to recover a RSA public key from a byte[] array of private key?

I'm wondering if it's possible to recover a RSA public key from private key? Private key loaded like this:

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

How to load the PublicKey from priva开发者_高级运维te? privateKey.getFormat returns null.


I am assuming that your GnuRSAPrivateKey is from the GNU Crypto project.

A GnuRSAPrivateKey instance contains the private key, with some extra values which are not strictly needed to implement RSA, but are still welcome for performance (using the Chinese Remainder Theorem) and for security (the public exponent is useful for masking, which helps against timing attacks). Therefore, this private key also contains the public key.

So this should work:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜