0
votes

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?

1

1 Answers

0
votes

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);