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


Python st_common.a2b_hex方法代码示例

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


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

示例1: t2b

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def t2b(t):
    """Convert a text string with bytes in hex form to a byte string"""
    clean = rws(t)
    if len(clean)%2 == 1:
        raise ValueError("Even number of characters expected")
    return a2b_hex(clean) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:8,代码来源:test_pkcs1_oaep.py

示例2: t2b

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def t2b(t):
    """Convert a text string with bytes in hex form to a byte string"""
    clean = b(rws(t))
    if len(clean)%2 == 1:
        print clean
        raise ValueError("Even number of characters expected")
    return a2b_hex(clean) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:9,代码来源:test_pkcs1_15.py

示例3: t2b

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def t2b(t):
    """Convert a text string with bytes in hex form to a byte string"""
    clean = b(rws(t))
    if len(clean)%2 == 1:
        raise ValueError("Even number of characters expected")
    return a2b_hex(clean) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:8,代码来源:test_pkcs1_15.py

示例4: t2b

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def t2b(t):
    """Convert a text string with bytes in hex form to a byte string"""
    clean = b(rws(t))
    if len(clean)%2 == 1:
        raise ValueError("Even number of characters expected")
    return a2b_hex(clean)

# Helper class to count how many bytes have been requested
# from the key's private RNG, w/o counting those used for blinding 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:11,代码来源:test_pkcs1_pss.py

示例5: setUp

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def setUp(self):
        global RSA, Random, bytes_to_long
        from Crypto.PublicKey import RSA
        from Crypto import Random
        from Crypto.Util.number import bytes_to_long, inverse
        self.n = bytes_to_long(a2b_hex(self.modulus))
        self.p = bytes_to_long(a2b_hex(self.prime_factor))

        # Compute q, d, and u from n, e, and p
        self.q = divmod(self.n, self.p)[0]
        self.d = inverse(self.e, (self.p-1)*(self.q-1))
        self.u = inverse(self.p, self.q)    # u = e**-1 (mod q)

        self.rsa = RSA 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:16,代码来源:test_RSA.py

示例6: _exercise_primitive

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_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

示例7: _exercise_public_primitive

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

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

        # Exercise verification
        rsaObj.verify(new_ciphertext2, (bytes_to_long(plaintext),)) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:10,代码来源:test_RSA.py

示例8: _check_encryption

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_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

示例9: _check_decryption

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_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

示例10: _check_verification

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

        # Test verification
        t = (signature,)     # rsaObj.verify expects a tuple
        self.assertEqual(1, rsaObj.verify(message, t))

        # Test verification with overlong tuple (this is a
        # backward-compatibility hack to support some harmless misuse of the
        # API)
        t2 = (signature, '')
        self.assertEqual(1, rsaObj.verify(message, t2)) # extra garbage at end of tuple 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:15,代码来源:test_RSA.py

示例11: convert_tv

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def convert_tv(self, tv, as_longs=0):
        """Convert a test vector from textual form (hexadecimal ascii
        to either integers or byte strings."""
        key_comps = 'p','g','y','x'
        tv2 = {}
        for c in tv.keys():
            tv2[c] = a2b_hex(tv[c])
            if as_longs or c in key_comps or c in ('sig1','sig2'):
                tv2[c] = bytes_to_long(tv2[c])
        tv2['key']=[]
        for c in key_comps:
            tv2['key'] += [tv2[c]]
            del tv2[c]
        return tv2 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:16,代码来源:test_ElGamal.py

示例12: test_construct_4tuple

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def test_construct_4tuple(self):
        """DSA (default implementation) constructed key (4-tuple)"""
        (y, g, p, q) = [bytes_to_long(a2b_hex(param)) for param in (self.y, self.g, self.p, self.q)]
        dsaObj = self.dsa.construct((y, g, p, q))
        self._test_verification(dsaObj) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:7,代码来源:test_DSA.py

示例13: test_construct_5tuple

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def test_construct_5tuple(self):
        """DSA (default implementation) constructed key (5-tuple)"""
        (y, g, p, q, x) = [bytes_to_long(a2b_hex(param)) for param in (self.y, self.g, self.p, self.q, self.x)]
        dsaObj = self.dsa.construct((y, g, p, q, x))
        self._test_signing(dsaObj)
        self._test_verification(dsaObj) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:8,代码来源:test_DSA.py

示例14: _check_public_key

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def _check_public_key(self, dsaObj):
        k = a2b_hex(self.k)
        m_hash = a2b_hex(self.m_hash)

        # Check capabilities
        self.assertEqual(0, dsaObj.has_private())
        self.assertEqual(1, dsaObj.can_sign())
        self.assertEqual(0, dsaObj.can_encrypt())
        self.assertEqual(0, dsaObj.can_blind())

        # Check dsaObj.[ygpq] -> dsaObj.key.[ygpq] mapping
        self.assertEqual(dsaObj.y, dsaObj.key.y)
        self.assertEqual(dsaObj.g, dsaObj.key.g)
        self.assertEqual(dsaObj.p, dsaObj.key.p)
        self.assertEqual(dsaObj.q, dsaObj.key.q)

        # Check that private parameters are all missing
        self.assertEqual(0, hasattr(dsaObj, 'x'))
        self.assertEqual(0, hasattr(dsaObj.key, 'x'))

        # Sanity check key data
        self.assertEqual(1, dsaObj.p > dsaObj.q)            # p > q
        self.assertEqual(160, size(dsaObj.q))               # size(q) == 160 bits
        self.assertEqual(0, (dsaObj.p - 1) % dsaObj.q)      # q is a divisor of p-1

        # Public-only key objects should raise an error when .sign() is called
        self.assertRaises(TypeError, dsaObj.sign, m_hash, k)

        # Check __eq__ and __ne__
        self.assertEqual(dsaObj.publickey() == dsaObj.publickey(),True) # assert_
        self.assertEqual(dsaObj.publickey() != dsaObj.publickey(),False) # failIf 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:33,代码来源:test_DSA.py

示例15: _test_signing

# 需要导入模块: from Crypto.SelfTest import st_common [as 别名]
# 或者: from Crypto.SelfTest.st_common import a2b_hex [as 别名]
def _test_signing(self, dsaObj):
        k = a2b_hex(self.k)
        m_hash = a2b_hex(self.m_hash)
        r = bytes_to_long(a2b_hex(self.r))
        s = bytes_to_long(a2b_hex(self.s))
        (r_out, s_out) = dsaObj.sign(m_hash, k)
        self.assertEqual((r, s), (r_out, s_out)) 
开发者ID:adde88,项目名称:hostapd-mana,代码行数:9,代码来源:test_DSA.py


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