I\'ve seen a number of similar questions, but nothing has quite worked for me. I am simply trying to convert an RSA public key that\'s in PEM format that I\'ve retrieved from a
This doesn't answer the question, but I find the content relevant. Posting as an answer because it doesn't fit as a comment.
-----BEGIN -----
and -----END -----
.Mostly paraphrasing from ASN.1(wiki).
The following is an example of how to use a key factory in order to instantiate a DSA public key from its encoding. Assume Alice has received a digital signature from Bob. Bob also sent her his public key (in encoded format) to verify his signature. Alice then performs the following actions:
X509EncodedKeySpec bobPubKeySpec = new X509EncodedKeySpec(bobEncodedPubKey); KeyFactory keyFactory = KeyFactory.getInstance("DSA"); PublicKey bobPubKey = keyFactory.generatePublic(bobPubKeySpec);
...
Note that bobEncodedPubKey
is DER-encoded in this sample.
https://developer.android.com/reference/java/security/KeyFactory
Similar to what is done for DER, but do the following beforehand:
BEGIN
/END
delimitation, and(The question already shows code on how to do this.)