使用Scrypt和PBKDF2生成比特币钱包

时间:2016-10-10 05:26:59

标签: python cryptography bitcoin pbkdf2 scrypt

我正在尝试使用Scrypt和PBKDF2来实现根据以下公式生成比特币地址的脚本:

Image link to the formula

为此,我用Python语言创建了一个脚本,它甚至生成了地址,但我认为有一些错误,因为生成的地址不适用于相应的条目。预计将设置密码“ER8FT + HFjk0”和盐“7DpniYifN6c”,输出为地址“1J32CmwScqhwnNQ77cKv9q41JGwoZe2JYQ”。我的脚本将地址“13UYidJ8HbHRZ9hTFgHQxWmq2LNyzeUxKV”返回到这些条目。

 import pyscrypt
 from passlib.utils.pbkdf2 import get_prf, pbkdf2
 from coinkit import BitcoinKeypair

 def getWallet(phrase, saltPhrase):
     s1 = pyscrypt.hash(password=phrase, salt=saltPhrase, N=16, r=8, p=1, dkLen=32)
     s2 = pbkdf2(phrase, saltPhrase, 1, keylen=32, prf='hmac-sha256')

     newWallet = BitcoinKeypair.from_passphrase(s1+s2)
     return {"walletAddress":newWallet.address(), "walletWif":newWallet.wif_pk()}

 myWallet = getWallet("ER8FT+HFjk0", "7DpniYifN6c")
 print "Address: "+myWallet["walletAddress"]+"\nWif: "+myWallet["walletWif"]

注意:要使脚本正常工作,您需要安装一些库:

 pip install pyscrypt passlib coinkit

如果你能帮助我,我将不胜感激。谢谢。

0 个答案:

没有答案
相关问题