0

I read a lot of similar topics on SO but I am still a little bit confused.

I have a public key in .pub format (pure public key). The question is if it is possible to read it in this format in Java. I am able to read public key if it has .der format.

    RSAPublicKey publicKey
            = (RSAPublicKey) KeyFactory.getInstance("RSA").
            generatePublic(new X509EncodedKeySpec(FileCopyUtils.
                    copyToByteArray(resource.getInputStream())));

Works fine. However it is not working for .pub format. If the only option is to read der file how should I correctly convert .pub to .der. Thanks in advance for any help.

  • See [RSA Public Key format](http://stackoverflow.com/questions/12749858/rsa-public-key-format) – Robert May 17 '16 at 12:28
  • @Robert Thank you for the link - I read it before. I understand that there are differences in these formats. My question is if it is possible to load public key in pub format in java or if there some tools /libs to transform from pub to der. – Tomasz Maciejewski May 18 '16 at 07:21
  • Just ignore the text header and read only the base64 encoded part. Apply Base64Decode and you should have the DER form. – Robert May 18 '16 at 08:00
  • @Robert Thank you very much :) I will extend my question with code in Java including your advice in free time. – Tomasz Maciejewski May 23 '16 at 08:43

0 Answers0