当前位置: 首页>>代码示例>>Python>>正文


Python random.StrongRandom方法代码示例

本文整理汇总了Python中Crypto.Random.random.StrongRandom方法的典型用法代码示例。如果您正苦于以下问题:Python random.StrongRandom方法的具体用法?Python random.StrongRandom怎么用?Python random.StrongRandom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypto.Random.random的用法示例。


在下文中一共展示了random.StrongRandom方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: verifyMsg

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import StrongRandom [as 别名]
def verifyMsg(text, imported_key, sig):

    seq2 = asn1.DerSequence()
    data = '\n'.join(imported_key.strip().split('\n')[1:-1]).decode('base64')
    seq2.decode(data)
    p, q, g, y, x = seq2[1:]

    key2 = DSA.construct((y, g, p, q, x))
    
    k1 = random.StrongRandom().randint(1,key2.q-1)

    h = SHA.new(text).digest()

    a = key2.verify(h, sig)
    
    return a 
开发者ID:lockedbyte,项目名称:cryptovenom,代码行数:18,代码来源:main.py

示例2: signMsg

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import StrongRandom [as 别名]
def signMsg(text, imported_key):

    seq2 = asn1.DerSequence()
    data = '\n'.join(imported_key.strip().split('\n')[1:-1]).decode('base64')
    seq2.decode(data)
    p, q, g, y, x = seq2[1:]

    key2 = DSA.construct((y, g, p, q, x))
    
    k1 = random.StrongRandom().randint(1,key2.q-1)

    h = SHA.new(text).digest()

    sig = key2.sign(h, k1)
    
    return sig 
开发者ID:lockedbyte,项目名称:cryptovenom,代码行数:18,代码来源:main.py

示例3: test_nonce_reuse

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import StrongRandom [as 别名]
def test_nonce_reuse(secret_key=DSA.generate(1024)):
            # choose a "random" - k :)  this time random is static in order to allow this attack to work
            k = random.StrongRandom().randint(1, secret_key.q - 1)
            # sign two messages using the same k
            samples = (Tests.Dsa.signMessage(secret_key, "This is a signed message!", k),
                       Tests.Dsa.signMessage(secret_key, "Another signed Message -  :)", k))
            logger.debug("generated sample signatures: %s" % repr(samples))
            signatures = [DsaSignature(sig, h, pubkey) for h, sig, pubkey in samples]
            logger.debug("Signature Objects: %r" % signatures)

            two_sigs = []
            for sig in signatures:
                two_sigs.append(sig)
                if not len(two_sigs) == 2:
                    continue
                sample = two_sigs.pop(0)
                logger.debug("%r - recovering privatekey from nonce reuse..." % sample)
                assert (sample.x is None)  # not yet resolved
                sample.recover_nonce_reuse(two_sigs[0])
                assert (sample.x is not None)  # privkey recovered
                assert (sample.privkey == secret_key)
                logger.debug("%r - Private key recovered! \n%s" % (sample, sample.export_key())) 
开发者ID:tintinweb,项目名称:ecdsa-private-key-recovery,代码行数:24,代码来源:test_ecdsa_key_recovery.py

示例4: signMessage

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import StrongRandom [as 别名]
def signMessage(privkey, msg, k=None):

            """
            create DSA signed message
            @arg privkey ... privatekey as DSA obj
            @arg msg     ... message to sign
            @arg k       ... override random k
            """

            k = k or random.StrongRandom().randint(2, privkey.q - 1)
            # generate msg hash
            # sign the messages using privkey
            h = SHA.new(msg).digest()
            r, s = privkey.sign(h, k)
            return h, (r, s), privkey.publickey() 
开发者ID:tintinweb,项目名称:ecdsa-private-key-recovery,代码行数:17,代码来源:test_ecdsa_key_recovery.py

示例5: create_rng

# 需要导入模块: from Crypto.Random import random [as 别名]
# 或者: from Crypto.Random.random import StrongRandom [as 别名]
def create_rng(tag):
    rng = StrongRandom(SHAKE128.new(data=tag))
    return rng 
开发者ID:vcheckzen,项目名称:FODI,代码行数:5,代码来源:test_modexp.py


注:本文中的Crypto.Random.random.StrongRandom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。