當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。