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


Python st_common.b2a_hex方法代码示例

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


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

示例1: _exercise_primitive

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import b2a_hex [as 别名]
def _exercise_primitive(self, rsaObj):
        # Since we're using a randomly-generated key, we can't check the test
        # vector, but we can make sure encryption and decryption are inverse
        # operations.
        ciphertext = a2b_hex(self.ciphertext)

        # Test decryption
        plaintext = rsaObj.decrypt((ciphertext,))

        # Test encryption (2 arguments)
        (new_ciphertext2,) = rsaObj.encrypt(plaintext, b(""))
        self.assertEqual(b2a_hex(ciphertext), b2a_hex(new_ciphertext2))

        # Test blinded decryption
        blinding_factor = Random.new().read(len(ciphertext)-1)
        blinded_ctext = rsaObj.blind(ciphertext, blinding_factor)
        blinded_ptext = rsaObj.decrypt((blinded_ctext,))
        unblinded_plaintext = rsaObj.unblind(blinded_ptext, blinding_factor)
        self.assertEqual(b2a_hex(plaintext), b2a_hex(unblinded_plaintext))

        # Test signing (2 arguments)
        signature2 = rsaObj.sign(ciphertext, b(""))
        self.assertEqual((bytes_to_long(plaintext),), signature2)

        # Test verification
        self.assertEqual(1, rsaObj.verify(ciphertext, (bytes_to_long(plaintext),))) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:28,代码来源:test_RSA.py

示例2: _check_encryption

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import b2a_hex [as 别名]
def _check_encryption(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)
        ciphertext = a2b_hex(self.ciphertext)

        # Test encryption (2 arguments)
        (new_ciphertext2,) = rsaObj.encrypt(plaintext, b(""))
        self.assertEqual(b2a_hex(ciphertext), b2a_hex(new_ciphertext2)) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:9,代码来源:test_RSA.py

示例3: _check_decryption

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import b2a_hex [as 别名]
def _check_decryption(self, rsaObj):
        plaintext = a2b_hex(self.plaintext)
        ciphertext = a2b_hex(self.ciphertext)

        # Test plain decryption
        new_plaintext = rsaObj.decrypt((ciphertext,))
        self.assertEqual(b2a_hex(plaintext), b2a_hex(new_plaintext))

        # Test blinded decryption
        blinding_factor = Random.new().read(len(ciphertext)-1)
        blinded_ctext = rsaObj.blind(ciphertext, blinding_factor)
        blinded_ptext = rsaObj.decrypt((blinded_ctext,))
        unblinded_plaintext = rsaObj.unblind(blinded_ptext, blinding_factor)
        self.assertEqual(b2a_hex(plaintext), b2a_hex(unblinded_plaintext)) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:16,代码来源:test_RSA.py


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