21Haz
How to generate an X9.62 encoded ECDSA prime256v1 private key using OpenSSL?
I created a private key using Analog device's signtool. It can be found part of "CrossCore Embedded Studio for Blackfin, SHARC and SHARC+ - Release (Rev. 2.12.0)". Link: https://www.analog.com/en/resources/evaluation-hardware-and-software/software/adswt-cces.html#software-relatedsoftware
$ signtool genkeypair -algo ecdsa256 -outfile keychain-cces.der
$ openssl asn1parse -inform DER -in keychain-cces.der
0:d=0 hl=2 l= 119 cons: SEQUENCE
2:d=1 hl=2 l= 1 prim: INTEGER :01
5:d=1 hl=2 l= 32 prim: OCTET STRING [HEX DUMP]:EC75CF473BF6CE76B18854B313F61956A82C4C0D7A4BB57D3270C2110D881752
39:d=1 hl=2 l= 10 cons: cont [ 0 ]
41:d=2 hl=2 l= 8 prim: OBJECT :prime256v1
51:d=1 hl=2 l= 68 cons: cont [ 1 ]
53:d=2 hl=2 l= 66 prim: BIT STRING
$
Based on the reference of https://stackoverflow.com/questions/59552240/are-openssl-generated-pem-keys-compatible-with-erlang-crypto, I found it is a X9.62 encoded private key.
I tried to create the similar key using the OpenSSL tool.
$ openssl ecparam -genkey -name prime256v1 -out openssl-ecdsa-private.pem
$ cat openssl-ecdsa-private.pem
-----BEGIN EC PARAMETERS-----
BggqhkjOPQMBBw==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEICTwYkKdcSTmpf+wgxBn58VoK8W13mW3xgxZPvWLyFusoAoGCCqGSM49
AwEHoUQDQgAEroAqSJuYhV3I0vZCPrd1C7OditQ8rab2gAJrcBJbgRzdw8Uu22Mt
DwMmFnkm8Tqh+elfkJDXoNQgA5G7tlnIeQ==
-----END EC PRIVATE KEY-----
$
$ openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in openssl-ecdsa-private.pem -out openssl-ecdsa-private.der
$ openssl asn1parse -inform DER -in openssl-ecdsa-private.der
0:d=0 hl=3 l= 135 cons: SEQUENCE
3:d=1 hl=2 l= 1 prim: INTEGER :00
6:d=1 hl=2 l= 19 cons: SEQUENCE
8:d=2 hl=2 l= 7 prim: OBJECT :id-ecPublicKey
17:d=2 hl=2 l= 8 prim: OBJECT :prime256v1
27:d=1 hl=2 l= 109 prim: OCTET STRING [HEX DUMP]:306B020101042024F062429D7124E6A5FFB0831067E7C5682BC5B5DE65B7C60C593EF58BC85BACA14403420004AE802A489B98855DC8D2F6423EB7750BB39D8AD4
3CADA6F680026B70125B811CDDC3C52EDB632D0F0326167926F13AA1F9E95F9090D7A0D4200391BBB659C879
$
Why keychain-cces.der and openssl-ecdsa-private.der ASN.1 parse outputs are different?
I want to get a private key with OpenSSL similar to singtool geneated. How to generate it?
Thanks, GK