1

I am trying to get an RSAPublicKey object from a public key file which is PEM encoded . The file is in the format given below

-----BEGIN PUBLIC KEY-----
M67sdjFDSSTRWE%$HGF£$"F£$$£%$ etc...
-----END PUBLIC KEY-----enter code here

I would like to get the modulus and exponent by reading this file. I have tried to do base64 decode and used the following

RSAPublicKey rsakey = (RSAPublicKey)PublicKeyDecoder.decode(decoded, "X509");

but it throws an InvalidKeyEncodingException.

Is there any way I can get an RSAPublicKey object from a PEM encoded public key file?

Nate
  • 31,017
  • 13
  • 83
  • 207
rfsk2010
  • 8,571
  • 4
  • 32
  • 46
  • Try removing the begin and end lines, as seen here http://stackoverflow.com/questions/7216969/getting-rsa-private-key-from-pem-base64-encoded-private-key-file – Anil Vaitla Apr 10 '13 at 16:42
  • @DuncanJones, in general, it doesnt work well to tag these questions with the java tag. BlackBerry supports a small subset of standard Java libraries and the java tag always brings in tons of answers that don't work on BB Java. Just a heads-up. – Nate Apr 11 '13 at 00:21
  • 2
    @DuncanJones, There is a BlackBerry-10 tag and the BlackBerry tag is quite clear that it should only be used for the 'legacy' BlackBerry OSs 7 and below. Not many SO users follow that however. – Richard Apr 11 '13 at 16:00
  • 1
    @Nate I asked a [meta question](http://meta.stackexchange.com/q/176088/192221) on the subject. In the interest of non-clutter, I'll be deleting my comments under this question so we can focus on the answer. – Duncan Jones Apr 12 '13 at 07:23
  • It would be really nice if the "BlackBerry" tag description could stop trying to be Wikipedia, and explain how the tag is actually used on SO. I submitted a suggested change to that effect, but it was ignored. – Michael Donohue Apr 13 '13 at 04:36

0 Answers0