漫谈区块链

手动生成eth地址

2018-04-24  本文已影响627人  已不再更新_转移到qiita

安装

pip install ecdsa
pip install pysha3

python script

import binascii
import sha3
from ecdsa import SigningKey, SECP256k1

keccak = sha3.keccak_256()

priv = SigningKey.generate(curve=SECP256k1)
pub = priv.get_verifying_key().to_string()

keccak.update(pub)
address = "0x" + keccak.hexdigest()[24:]

priv_key = binascii.hexlify( priv.to_string())
pub_key = binascii.hexlify(pub)

print("Private key: " + priv_key.decode() )
print("Public key:  " + pub_key.decode() )
print("Address:     " + address)

#####

# Private key: 3be07e92f4cca9075422bbecb70423bae2d93cf322b59aa77d31275fd46c22df
# Public key:  fc5bfe85b2179d37d0b9cd380932706f841da92e4f20e60d630651eadb5b208102ee8946aad298142cefb764bb36571e454884207d66a3e0922b3987130507f1
# Address:     0xd38d3c226d0a86ce9932608edac39163fcbc550e

golang

package main

import (
    "encoding/hex"
    "fmt"

    "github.com/ethereum/go-ethereum/crypto"
)

func main() {
    genEthAddr()
}

func genEthAddr() {
    key, _ := crypto.GenerateKey()

    privateKey := hex.EncodeToString(key.D.Bytes())
    address := crypto.PubkeyToAddress(key.PublicKey).Hex()

    fmt.Printf("privateKey: 0x%s\n", privateKey)
    fmt.Printf("addr: %s\n", address)
}

// GOOS=linux GOARCH=amd64 go build -o main main.go && zip main.zip main


参考:
https://www.jianshu.com/p/efc6bfdf4988
https://www.bilibili.com/video/av27153321
https://zhuanlan.zhihu.com/p/34363341
https://www.myetherwallet.com/

上一篇 下一篇

猜你喜欢

热点阅读