Post
Topic
Board Development & Technical Discussion
Re: openssl making private/public keys for ethereum
by
sunsetblues
on 23/03/2018, 16:48:02 UTC
To sum up, the steps are (I've compressed the whole procedure to a smaller command list):

Code:
$  openssl ecparam -name secp256k1 -genkey -noout -outform DER | \
     openssl ec -inform DER -no_public -outform DER -out template.der
read EC key
writing EC key

$ head -c 7 template.der > header.bin
$ echo A114dad00000000000faced00000000000bad000000000decaf00c02bad02bad | xxd -r -p > key.bin
$ tail -c +40 template.der > footer.bin
$ cat header.bin key.bin footer.bin > private_key.der

$ cat private_key.der | openssl asn1parse -in - -inform DER
    0:d=0  hl=2 l=  46 cons: SEQUENCE          
    2:d=1  hl=2 l=   1 prim: INTEGER           :01
    5:d=1  hl=2 l=  32 prim: OCTET STRING      [HEX DUMP]:A114DAD00000000000FACED00000000000BAD000000000DECAF00C02BAD02BAD
   39:d=1  hl=2 l=   7 cons: cont [ 0 ]        
   41:d=2  hl=2 l=   5 prim: OBJECT            :secp256k1

$ openssl ec -inform DER -in private_key.der -no_public 2>/dev/null | \
    openssl ec -inform PEM -outform DER -out private_key_fixed.der 2>/dev/null

$ openssl ec -check -inform DER -in private_key_fixed.der -noout -text
read EC key
Private-Key: (256 bit)
priv:
    a1:14:da:d0:00:00:00:00:00:fa:ce:d0:00:00:00:
    00:00:ba:d0:00:00:00:00:de:ca:f0:0c:02:ba:d0:
    2b:ad
pub:
    04:9f:7d:cb:14:14:21:77:d7:b9:48:78:c4:59:b6:
    3a:16:f4:12:80:84:49:b7:8f:a1:7b:e6:4c:d3:7f:
    ed:57:a6:42:12:07:e6:ca:95:e0:c5:15:c3:5f:d5:
    8c:af:ac:a8:b0:e7:d6:07:a3:3a:2c:5c:b1:6a:de:
    28:af:83:15:f7
ASN1 OID: secp256k1
EC Key valid.

$ rm *bin template.der private_key.der

You should be good this time. Could you check ?
Thanks you!

That works as expected thank you! I really appreciate you taking the time to send the updated code. If I ever get another spendable merit I'll send it your way. ;0)