2

Let's assume the following private key (in hex): dd1cd59c4de2fa92e363dac282afe790a5193177d413b38e206b2b86b879ffbf.

I would like to sign a message with this private key via openSSL. OpenSSL requires a pem file as key. So I'm trying to convert the above hex string to a PEM file.

As far as I realized so far, I need to do the following steps:

  1. Add the following prefix to the hex string: 30740201010420.
  2. Add the following string after the hex string: a00706052b8104000aa144034200.
  3. Add the public key

So I ended up with the following hex string: 30740201010420dd1cd59c4de2fa92e363dac282afe790a5193177d413b38e206b2b86b879ffbfa00706052b8104000aa144034200049d0f70eed85345ca5c1c04563bed19608562c37d644061785a836e8f199155f2818a1e2661f9ed501d8f906611892099a9de5a7ea9f641ecb4dd75bbb63c2d5a.

I convert it to binary and base64 the result:

-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIN0c1ZxN4vqS42PawoKv55ClGTF31BOzjiBrK4a4ef+/oAcGBSuBBAAK
oUQDQgAEnQ9w7thTRcpcHARWO+0ZYIViw31kQGF4WoNujxmRVfKBih4mYfntUB2P
kGYRiSCZqd5afqn2Qey03XW7tjwtWg==
-----END EC PRIVATE KEY-----

Is this the proper way of doing it? Is this a valid PEM key?

jww
  • 97,681
  • 90
  • 411
  • 885
user2298995
  • 2,045
  • 3
  • 19
  • 27
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Jan 04 '18 at 04:17
  • 1
    Maybe try [openssl convert der to pem](https://www.google.com/search?q=openssl+convert+der+to+pem). Its a lot less fragile than your method. – jww Jan 04 '18 at 04:25
  • This question is not off-topic. Filezilla Server on 1 side which use DER format C#.NET X509Certificate2 class which use ASN.1 DER – Nolmë Informatique May 17 '18 at 17:57

0 Answers0