Reputation: 11
I am trying to get the modulus value of a private key using bouncy castle library. I was able to get PrivateKeyInfo object how can i get the modulus value from this?
Upvotes: 0
Views: 1070
Reputation: 400
You could do as follow (this code is for public key but yours should be similar)
PublicKey key = getPublicKey();
KeyFactory keyFac = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pkSpec = keyFac.getKeySpec(key,
RSAPublicKeySpec.class);
byte[] modulusBytes = pkSpec.getModulus().toByteArray();
modulusBytes = stripLeadingZeros(modulusBytes);
Upvotes: 0