karthik21
karthik21

Reputation: 11

How can i use bouncy castle to extract modulus value from PrivateKeyInfo object?

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

Answers (1)

Eledra Nguyen
Eledra Nguyen

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

Related Questions