Post
Topic
Board Bitcoin Technical Support
Merits 2 from 2 users
Re: Get private_key.pem from WIF format
by
dex1
on 07/03/2020, 12:06:50 UTC
⭐ Merited by Heisenberg_Hunter (1) ,ETFbitcoin (1)
To feed data to openssl it needs to be formatted rightly.
Following your example:

Code:
PRE_STRING=302e0201010420
YOUR_PRIVKEY=2d7238106df87d7b70f9d7cc4ff833ff9fad86aa5e50f8cf42689c238d70f723
secp256k1_ID=a00706052b8104000a

Concatenate and convert to a binary:

Code:
echo $PRE_STRING $YOUR_PRIVKEY $secp256k1_ID | xxd -r -p > btc_priv.key

And there you go:

Code:
openssl ec -noout -text -inform DER -in btc_priv.key
read EC key
Private-Key: (256 bit)
priv:
    2d:72:38:10:6d:f8:7d:7b:70:f9:d7:cc:4f:f8:33:
    ff:9f:ad:86:aa:5e:50:f8:cf:42:68:9c:23:8d:70:
    f7:23
pub:
    04:e6:2b:19:a8:86:b1:5f:b5:cb:ad:69:f7:7f:2c:
    1d:81:6c:da:32:d9:fb:85:0b:97:e8:10:6a:38:70:
    0c:4c:93:79:65:64:ff:5a:d4:96:3e:d4:1c:a8:3f:
    71:a7:08:72:b9:79:5b:09:dd:6c:b2:28:64:e3:58:
    c4:85:73:d9:a7
ASN1 OID: secp256k1

https://stackoverflow.com/questions/48101258/how-to-convert-an-ecdsa-key-to-pem-format/49213805#49213805