Skip to content

Instantly share code, notes, and snippets.

@Stmol
Forked from gadiener/generate-bitcoin-keys.sh
Created February 27, 2023 20:36
Show Gist options
  • Save Stmol/5156655fcfd21f159b57d5179f4208be to your computer and use it in GitHub Desktop.
Save Stmol/5156655fcfd21f159b57d5179f4208be to your computer and use it in GitHub Desktop.
OpenSSL commands to create a Bitcoin private/public keys from a ECDSA keypair
#!/bin/sh
PRIVATE_KEY="ECDSA"
PUBLIC_KEY="ECDSA.pub"
BITCOIN_PRIVATE_KEY="bitcoin"
BITCOIN_PUBLIC_KEY="bitcoin.pub"
echo "Generating private key"
openssl ecparam -genkey -name secp256k1 -rand /dev/random -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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment