Created
December 18, 2024 20:57
-
-
Save miguelmota/38ee73ed6d1c7dd1770e494541384909 to your computer and use it in GitHub Desktop.
Ethereum generate private key, public key, public address using openssl secp256k1 keccak-256sum bash
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
ethereum_generate_keys() { | |
# Generate the private key and public key | |
local key=$(openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout 2>/dev/null) | |
# Extract and clean the public key | |
local pub=$(echo "$key" | grep pub -A 5 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^04//') | |
# Extract and clean the private key | |
local priv=$(echo "$key" | grep priv -A 3 | tail -n +2 | tr -d '\n[:space:]:' | sed 's/^00//' | sed 's/^priv//') | |
# Generate the address | |
local address=0x$(echo "$pub" | keccak-256sum -x -l | tr -d ' -' | tail -c 41) | |
# Print the results | |
echo "Private Key: $priv" | |
echo "Public Key: $pub" | |
echo "Address: $address" | |
} | |
# Example | |
# $ ethereum_generate_keys | |
# Private Key: fb8b62ca8b89a19157ec0ab0191c9dfd8a0656f51f1887f8dd6eff19366c3b5d | |
# Public Key: 371a2b8dd0d70f0b005e88fad7b97d219337a8d192f929e212a93f28ecaa2d259906f96f627736b14a4008400303b0ee9567af2d12f260fd6ff165464db34a24 | |
# Address: 0x48e124660d29a74a49f7d4e833bec84b34d79353 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment