原文鏈接:http://www.reibang.com/p/9ebeabd55d30
經(jīng)常和密碼打交道的人估計(jì)都用過一款神器:openssl(介紹opessl的安裝和使用類的資料很多顾患,這里略過)亚侠。剛好這幾天在網(wǎng)上看到一篇文章介紹如何用openssl創(chuàng)建以太坊賬戶,而不是用geth命令創(chuàng)建。文章寫得挺好,有點(diǎn)長(zhǎng),又是英文,所以我在這里用自己的話簡(jiǎn)單重述其操作步驟并給予適當(dāng)?shù)难a(bǔ)充說明伦吠。
原文鏈接:https://kobl.one/blog/create-full-ethereum-keypair-and-address,
也請(qǐng)參考:https://wiki.openssl.org/index.php/Command_Line_Elliptic_Curve_Operations
通常來說Linux系統(tǒng)發(fā)行版都有md5sum魂拦、shasum等哈希工具安裝包毛仪,但是sha3和keccak哈希工具比較新,就得通過源碼編譯安裝了芯勘,步驟如下:
git clonehttps://github.com/maandree/libkeccak
cd libkeccak
make
make install
ldconfig
git clonehttps://github.com/maandree/sha3sum.git
cd sha3sum
make
make install
ldconfig
運(yùn)行openssl ecparam -list_curves命令可以查看其支持的曲線類型集合箱靴,以太坊和比特幣都是采用secp256k1曲線,生成橢圓曲線密鑰對(duì)的命令如下:
openssl ecparam-name secp256k1 -genkey -noout?|?openssl ec -text -noout
輸出:
read EC key
Private-Key: (256bit)
priv:
???00:8f:93:e9:e3:32:02:42:6f:9d:0d:b3:a5:d2:59:
???22:60:33:30:e2:d5:a2:42:d5:21:22:ee:f0:9a:da:
? ?a8:7a:70
pub:
? ?04:29:14:c6:39:87:99:3d:e5:38:e5:e4:47:83:3a:
???21:bc:2f:d0:a7:df:fb:6f:40:ab:ad:2f:56:7e:b5:
???99:dc:fa:c6:95:36:fe:be:ad:25:05:98:41:84:40:
???6b:40:8e:a4:68:f4:68:ea:a8:64:4e:33:21:da:02:
? ?19:cf:1b:b2:e3
ASN1 OID:secp256k1
私鑰以00開頭荷愕,公鑰以04開頭衡怀,做運(yùn)算時(shí)棍矛,需要去掉00或04以及冒號(hào),用awk抛杨,sed够委,tr等經(jīng)典文本工具可以自動(dòng)化去除,看操作者熟練程度了怖现,若不熟悉這些工具命令的復(fù)雜選項(xiàng)慨绳,就手動(dòng)復(fù)制到文本編輯器內(nèi)去除,注意力集中在密碼技術(shù)上真竖,而不是文本處理技術(shù),得到如下結(jié)果:
--私鑰厌小,32字節(jié)恢共,表示成64 個(gè)字符--
8f93e9e33202426f9d0db3a5d25922603330e2d5a242d52122eef09adaa87a70
--公鑰,64字節(jié)璧亚,表示成128個(gè)字符--
2914c63987993de538e5e447833a21bc2fd0a7dffb6f40abad2f567eb599dcfac69536febead2505984184406b408ea468f468eaa8644e3321da0219cf1bb2e3
執(zhí)行如下命令讨韭,對(duì)公鑰做keccak-256哈希運(yùn)算導(dǎo)出賬戶地址:
echo -n "2914c63987993de538e5e447833a21bc2fd0a7dffb6f40abad2f567eb599dcfac69536febead2505984184406b408ea468f468eaa8644e3321da0219cf1bb2e3" | keccak-256sum -x -l | tr -d ' -' | tail -c 41
輸出:
47dca4f48cf5f43fa359040afa57b548c92d4a5d
注意這個(gè)結(jié)果必須和geth導(dǎo)入私鑰時(shí)的輸出結(jié)果一致,否則肯定是在某個(gè)地方出現(xiàn)操作失誤了癣蟋,需重做實(shí)驗(yàn)透硝。接下來執(zhí)行g(shù)eth命令導(dǎo)入私鑰進(jìn)行測(cè)試:
echo "8f93e9e33202426f9d0db3a5d25922603330e2d5a242d52122eef09adaa87a70" > priv
geth account import priv
輸出:
Your new account is locked with a password. ?Please give a password. ?Do not forget this password.
Passphrase:
Repeat passphrase:
Address: {47dca4f48cf5f43fa359040afa57b548c92d4a5d}
查看一下生成的密鑰keystore文件:
cat ~/.ethereum/keystore/UTC--2018-03-21T11-11-11.848269178Z--47dca4f48cf5f43fa359040afa57b548c92d4a5d
輸出:
{"address":"47dca4f48cf5f43fa359040afa57b548c92d4a5d","crypto":{"cipher":"aes-128-ctr","ciphertext":"433cb3158778be8e5861acf245e4769b3e054c0d1e8be5bac9f979d6dcc7b16e","cipherparams":{"iv":"a64b76316e5d1a532d300b76f9171f9c"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"2b1f5e2a011a4cc979c53b7ec575fbbeedc6b5940d96967c8872f9a5225e70ec"},"mac":"eceb8bdc070739c1659c5ccb73eac08364068f81f6c930b52ecdce1415d39c87"},"id":"aaa8d243-12fd-43f0-b24a-411b0ad6cddc","version":3}
進(jìn)入Quorum控制臺(tái)(Quorum和Geth相比,好處就是把gasPrice改為0了疯搅,這樣在轉(zhuǎn)賬測(cè)試計(jì)算賬戶余額的時(shí)候濒生,不用考慮礦工費(fèi)問題),測(cè)試一下看看:
>eth.getBalance(eth.coinbase)
9.98796449e+26
>eth.getBalance("47dca4f48cf5f43fa359040afa57b548c92d4a5d")
0
>eth.sendTransaction({from: eth.coinbase, to:"47dca4f48cf5f43fa359040afa57b548c92d4a5d", value: web3.toWei(100,"ether")})
"0x9001c52ebcda139994d42757c01c96e7e82fec6ac0a853d9fc9be3b505235c08"
>eth.getBalance("47dca4f48cf5f43fa359040afa57b548c92d4a5d")
100000000000000000000
>personal.unlockAccount("47dca4f48cf5f43fa359040afa57b548c92d4a5d","123456", 5000)
true
>eth.sendTransaction({from:"47dca4f48cf5f43fa359040afa57b548c92d4a5d", to: eth.coinbase, value:web3.toWei(9, "ether")})
"0x5073419262b953a5cff8bf31ab3b195c471b4a69d1f18d2cd24dc960277d0be3"
>eth.getBalance("47dca4f48cf5f43fa359040afa57b548c92d4a5d")
91000000000000000000
>eth.getBalance(eth.coinbase)
9.98796358e+26
>
作者:呂慶浩
鏈接:http://www.reibang.com/p/9ebeabd55d30
CAUTION!?if your final address looks like?*0xdcc703c0E500B653Ca82273B7BFAd8045D85a470*?this means you have hashed an empty public key. Sending funds to this address will lock them forever! People made this mistake before as shown on?etherscan.