Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@daragao
Created August 9, 2019 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daragao/f2ca6d568ce367a464a5ea41fb2e3233 to your computer and use it in GitHub Desktop.
Save daragao/f2ca6d568ce367a464a5ea41fb2e3233 to your computer and use it in GitHub Desktop.
script to generate Ethereum private key, public key, and address
#!/bin/bash
#Libs used for keccak-256sum
#https://github.com/maandree/libkeccak.git
#https://github.com/maandree/argparser.git
#https://github.com/maandree/sha3sum.git
# Generate the private and public keys
KEY="$(openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout 2> /dev/null)"
echo "$KEY"
# Extract the public key and remove the EC prefix 0x04
PUB="$(echo "$KEY" | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//')"
echo "Public key:" $PUB
# Extract the private key and remove the leading zero byte
PRIV="$(echo "$KEY" | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//')"
echo "Private key:" $PRIV
# Generate the hash and take the address part
ADDRESS="$(echo "$PUB" | keccak-256sum -x -l | tr -d ' -' | tail -c 41)"
echo "Address:" $ADDRESS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment