Created
August 9, 2019 11:02
-
-
Save daragao/f2ca6d568ce367a464a5ea41fb2e3233 to your computer and use it in GitHub Desktop.
script to generate Ethereum private key, public key, and address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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