3
3
I found the following code online and apparently it works. But I don't understand the lines which extract the Bitcoin compatible private/public key from the created ECDSA keypair.
FILE_NAME=$1
PRIVATE_KEY=${FILE_NAME}_private.pem
PUBLIC_KEY=${FILE_NAME}_public.pem
BITCOIN_PRIVATE_KEY=bitcoin_${FILE_NAME}_private.key
BITCOIN_PUBLIC_KEY=bitcoin_${FILE_NAME}_public.key
echo "Generating private key"
openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out $PRIVATE_KEY
echo "Generating public key"
openssl ec -in $PRIVATE_KEY -pubout -out $PUBLIC_KEY
echo "Generating BitCoin private key"
openssl ec -in $PRIVATE_KEY -outform DER|tail -c +8|head -c 32|xxd -p -c 32 > $BITCOIN_PRIVATE_KEY
echo "Generating BitCoin public key"
openssl ec -in $PRIVATE_KEY -pubout -outform DER|tail -c 65|xxd -p -c 65 > $BITCOIN_PUBLIC_KEY
echo "Files created!"
If someone could explain, that would be nice
1Ok, so the "magic" I was missing is basically a format conversion.Thanks! – soupdiver – 2017-09-17T15:59:33.490
@Adrew
echo "Generating BitCoin public key" openssl ec -in $PRIVATE_KEY -pubout -outform DER|tail -c 65|xxd -p -c 65 > $BITCOIN_PUBLIC_KEYthis takes private key not public key in pem version. Why I have to create $PUBLIC_KEY ? – monkeyUser – 2019-01-24T14:53:07.823You need the public key in pem form so that you can do public key operations with openssl. However, depending on what you are doing, it may not be necessary. I do not know what the original author's intent for this code was; my answer is only explaining what it does. – Andrew Chow – 2019-01-24T17:19:06.443