mnemonic.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:blockhooks 作者: EthereumWebhooks 项目源码 文件源码
def mnemonic_to_seed(mnemonic_phrase,passphrase=u''):
    try:
        from hashlib import pbkdf2_hmac
        def pbkdf2_hmac_sha256(password,salt,iters=2048):
            return pbkdf2_hmac(hash_name='sha512',password=password,salt=salt,iterations=iters)
    except:
        try:
            from Crypto.Protocol.KDF import PBKDF2
            from Crypto.Hash import SHA512,HMAC

            def pbkdf2_hmac_sha256(password,salt,iters=2048):
                return PBKDF2(password=password,salt=salt,dkLen=64,count=iters,prf=lambda p,s: HMAC.new(p,s,SHA512).digest())
        except:
            try:

                from pbkdf2 import PBKDF2
                import hmac
                def pbkdf2_hmac_sha256(password,salt,iters=2048):
                    return PBKDF2(password,salt, iterations=iters, macmodule=hmac, digestmodule=hashlib.sha512).read(64)
            except:
                raise RuntimeError("No implementation of pbkdf2 was found!")

    return pbkdf2_hmac_sha256(password=mnemonic_phrase,salt='mnemonic'+passphrase)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号