RSA根据modulus,exponent生成公钥

// 根据n、e值还原公钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public static PublicKey getPublicKey(String modulus, String publicExponent)

throws NoSuchAlgorithmException, InvalidKeySpecException {

BigInteger bigIntModulus = new BigInteger(modulus,16);

BigInteger bigIntPrivateExponent = new BigInteger(publicExponent,16);

RSAPublicKeySpec keySpec = new RSAPublicKeySpec(bigIntModulus, bigIntPrivateExponent);

KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey publicKey = keyFactory.generatePublic(keySpec);

return publicKey;

}