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


Python FortunaGenerator.AESGenerator方法代码示例

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


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

示例1: test_generator

# 需要导入模块: from Crypto.Random.Fortuna import FortunaGenerator [as 别名]
# 或者: from Crypto.Random.Fortuna.FortunaGenerator import AESGenerator [as 别名]
def test_generator(self):
        """FortunaGenerator.AESGenerator"""
        fg = FortunaGenerator.AESGenerator()

        # We shouldn't be able to read data until we've seeded the generator
        self.assertRaises(Exception, fg.pseudo_random_data, 1)
        self.assertEqual(0, fg.counter.next_value())

        # Seed the generator, which should set the key and increment the counter.
        fg.reseed(b("Hello"))
        self.assertEqual(b("0ea6919d4361551364242a4ba890f8f073676e82cf1a52bb880f7e496648b565"), b2a_hex(fg.key))
        self.assertEqual(1, fg.counter.next_value())

        # Read 2 full blocks from the generator
        self.assertEqual(b("7cbe2c17684ac223d08969ee8b565616") +       # counter=1
                         b("717661c0d2f4758bd6ba140bf3791abd"),        # counter=2
            b2a_hex(fg.pseudo_random_data(32)))

        # Meanwhile, the generator will have re-keyed itself and incremented its counter
        self.assertEqual(b("33a1bb21987859caf2bbfc5615bef56d") +       # counter=3
                         b("e6b71ff9f37112d0c193a135160862b7"),        # counter=4
            b2a_hex(fg.key))
        self.assertEqual(5, fg.counter.next_value())

        # Read another 2 blocks from the generator
        self.assertEqual(b("fd6648ba3086e919cee34904ef09a7ff") +       # counter=5
                         b("021f77580558b8c3e9248275f23042bf"),        # counter=6
            b2a_hex(fg.pseudo_random_data(32)))


        # Try to read more than 2**20 bytes using the internal function.  This should fail.
        self.assertRaises(AssertionError, fg._pseudo_random_data, 2**20+1) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:34,代码来源:test_FortunaGenerator.py


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