0

Using this tutorial, I created a Java program what can sign a document with SHA256withRSA algorithm. In the output I get a public key and a signature file.

I try to verify my file with openssl, but I can't... I was searching on the net and I found that I need to have a standard .pem key maybe, so my question is: How can I convert my key to pem format? Or can I generate a .pem key in Java? And if it's a wrong way, how can I verify my signature?

Süli Patrik
  • 85
  • 2
  • 8
  • Try to use a Key Store Explorer (http://keystore-explorer.org/), may be it could convert keys/certificates to a desired format – lospejos Jan 28 '17 at 11:34
  • You should provide the Java code you used to produce the signature, and the OpenSSL commands you used to verify the signature. – jww Jan 28 '17 at 13:30

1 Answers1

1

A PEM file contains the public key binary data encoded in base64 and splitted in lines of 64 characters. The file has also the header -----BEGIN PUBLIC KEY----- and the footer -----END PUBLIC KEY-----

Java has not a native converter to PEM but you can use bouncycastle

PEMWriter pemWriter = new PEMWriter(new FileWriter(file));
pemWriter.writeObject(publicKey);
pemWriter.flush();
pemWriter.close();

Alternatively you can verify a signature with openssl using a binary key format using

  -keyform DER

Then save the content of your publicKey in a file

 byte publicKeyDer[] = publicKey.getEncoded()
pedrofb
  • 37,271
  • 5
  • 94
  • 142