Answer the question
In order to leave comments, you need to log in
How to get RSAPublicKey from RSAPrivateKey in >=Android-4.3?
Hello!
My task is to get RSAPublicKey from an object of type RSAPrivateKey (or, to put it more simply, "pull out" a public key from a private one).
Prior to Android 4.3, this approach worked in my application:
RSAPrivateCrtKey private_key = (RSAPrivateCrtKey) KeyFactory.getInstance("RSA")
.generatePrivate(new PKCS8EncodedKeySpec(encoded_byte_array));
PublicKey public_key = KeyFactory.getInstance("RSA")
.generatePublic(new RSAPublicKeySpec(private_key.getModulus(),
private_key.getPublicExponent()));
Answer the question
In order to leave comments, you need to log in
They changed the API from version 4.2 to OpenSSL lib
There is a comprehensive solution here. In your case, the code will look like this:
KeyFactory fact = KeyFactory.getInstance("RSA");
Key pubKey = fact.generatePublic(new RSAPublicKeySpec(m, e));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question