本文整理汇总了Python中Crypto.Util.randpool.RandomPool方法的典型用法代码示例。如果您正苦于以下问题:Python randpool.RandomPool方法的具体用法?Python randpool.RandomPool怎么用?Python randpool.RandomPool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypto.Util.randpool
的用法示例。
在下文中一共展示了randpool.RandomPool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runTest
# 需要导入模块: from Crypto.Util import randpool [as 别名]
# 或者: from Crypto.Util.randpool import RandomPool [as 别名]
def runTest(self):
"""Crypto.Util.randpool.RandomPool"""
# Import the winrandom module and try to use it
from Crypto.Util.randpool import RandomPool
sys.stderr.write("SelfTest: You can ignore the RandomPool_DeprecationWarning that follows.\n")
rpool = RandomPool()
x = rpool.get_bytes(16)
y = rpool.get_bytes(16)
self.assertNotEqual(x, y)
self.assertNotEqual(rpool.entropy, 0)
rpool.randomize()
rpool.stir('foo')
rpool.add_event('foo')
示例2: randomSource
# 需要导入模块: from Crypto.Util import randpool [as 别名]
# 或者: from Crypto.Util.randpool import RandomPool [as 别名]
def randomSource(r = randpool.RandomPool().get_bytes):
return struct.unpack('H', r(2))[0]
示例3: createKey
# 需要导入模块: from Crypto.Util import randpool [as 别名]
# 或者: from Crypto.Util.randpool import RandomPool [as 别名]
def createKey(keySize=32):
"""Create a random key.
@param keySize: a positive C{int} key length.
@return: a random string of length C{keySize}.
"""
try:
return randpool.RandomPool(512).get_bytes(keySize)
except AssertionError:
# An AssertionError can come from Crypto/Random/_UserFriendlyRNG.py,
# which produces an error "PID check failed. RNG must be re-initialized
# after fork(). Hint: Try Random.atfork()". This seems to only happen
# when running locally (in development mode).
atfork()
return randpool.RandomPool(512).get_bytes(keySize)
示例4: _createIV
# 需要导入模块: from Crypto.Util import randpool [as 别名]
# 或者: from Crypto.Util.randpool import RandomPool [as 别名]
def _createIV():
"""Create a 16-byte initialization vector.
@return: a C{str} initialization vector.
"""
try:
return randpool.RandomPool(512).get_bytes(16)
except AssertionError:
# An AssertionError can come from Crypto/Random/_UserFriendlyRNG.py,
# which produces an error "PID check failed. RNG must be re-initialized
# after fork(). Hint: Try Random.atfork()". This seems to only happen
# when running locally (in development mode).
atfork()
return randpool.RandomPool(512).get_bytes(16)