Generating Ethereum Accounts and Addresses

Generate a new Private Key and associated Public Address

#!/usr/bin/python3

import sha3
from ecdsa import SigningKey, SECP256k1

keccak = sha3.keccak_256()
sk = SigningKey.generate(curve=SECP256k1)
keccak.update(sk.get_verifying_key().to_string())
address = "0x{0}".format(keccak.hexdigest()[24:])
private = sk.to_string().hex()
print("Private Key   : {0}n"
      "Public Address: {1}n".format(private,address))

Generate the Public Address from a Private Key expressed in hex

#!/usr/bin/python3

import sha3
import binascii
from ecdsa import SigningKey, SECP256k1

private = binascii.unhexlify('8135253f1f5269f00b1a3740c463d478da369b6433f31139a4337250fc249e83')
keccak = sha3.keccak_256()
keccak.update(SigningKey.from_string(private, curve=SECP256k1).get_verifying_key().to_string())
address = "0x{0}".format(keccak.hexdigest()[24:])
print("Public Address: {0}".format(address))

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.