如何将JSON字符串转换为RSA公钥
或
String s = "AAA";
想要将s
转换为公钥
getPublicKey(
jArray.get(i).getAsJsonObject().get("e").getAsString(),
jArray.get(i).getAsJsonObject().get("n").getAsString()
)
public static PublicKey getPublicKey (String modulusB64u, String exponentB64u)
throws NoSuchAlgorithmException, InvalidKeySpecException{
//conversion to BigInteger. I have transformed to Hex because new BigDecimal(byte) does not work for me
byte exponentB[] = Base64.getUrlDecoder().decode(exponentB64u);
byte modulusB[] = Base64.getUrlDecoder().decode(modulusB64u);
BigInteger exponent = new BigInteger(toHexFromBytes(exponentB), 16);
BigInteger modulus = new BigInteger(toHexFromBytes(modulusB), 16);
//Build the public key
RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent);
KeyFactory factory = KeyFactory.getInstance("RSA");
PublicKey pub = factory.generatePublic(spec);
return pub;
}
我想将JSON字符串的值转换为公钥,而不是生成公钥。