本文整理汇总了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
示例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
示例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()))
示例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()
示例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