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


Python AES.block_size方法代码示例

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


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

示例1: encrypt_credential

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def encrypt_credential(raw):
    """
    Encodes data

    :param data: Data to be encoded
    :type data: str
    :returns:  string -- Encoded data
    """
    # pylint: disable=invalid-name,import-error
    import base64
    try:  # The crypto package depends on the library installed (see Wiki)
        from Crypto import Random
        from Crypto.Cipher import AES
        from Crypto.Util import Padding
    except ImportError:
        from Cryptodome import Random
        from Cryptodome.Cipher import AES
        from Cryptodome.Util import Padding
    raw = bytes(Padding.pad(data_to_pad=raw.encode('utf-8'), block_size=__BLOCK_SIZE__))
    iv = Random.new().read(AES.block_size)
    cipher = AES.new(get_crypt_key(), AES.MODE_CBC, iv)
    return base64.b64encode(iv + cipher.encrypt(raw)).decode('utf-8') 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:24,代码来源:credentials.py

示例2: decrypt_credential

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def decrypt_credential(enc, secret=None):
    """
    Decodes data

    :param data: Data to be decoded
    :type data: str
    :returns:  string -- Decoded data
    """
    # pylint: disable=invalid-name,import-error
    import base64
    try:  # The crypto package depends on the library installed (see Wiki)
        from Crypto.Cipher import AES
        from Crypto.Util import Padding
    except ImportError:
        from Cryptodome.Cipher import AES
        from Cryptodome.Util import Padding
    enc = base64.b64decode(enc)
    iv = enc[:AES.block_size]
    cipher = AES.new(secret or get_crypt_key(), AES.MODE_CBC, iv)
    decoded = Padding.unpad(
        padded_data=cipher.decrypt(enc[AES.block_size:]),
        block_size=__BLOCK_SIZE__)
    return decoded 
开发者ID:CastagnaIT,项目名称:plugin.video.netflix,代码行数:25,代码来源:credentials.py

示例3: generate_iv

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def generate_iv() -> bytes:
        return Random.new().read(AES.block_size) 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:4,代码来源:aes_handler.py

示例4: aes_cbc_encrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def aes_cbc_encrypt(plain_text: bytes, key: bytes, iv: bytes = b''):
        if len(iv) == 0:
            iv = AESHandler.generate_iv()
        cipher = AES.new(key=key, mode=AES.MODE_CBC, iv=iv)
        return cipher.IV, cipher.encrypt(pad(plain_text, AES.block_size)) 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:7,代码来源:aes_handler.py

示例5: aes_cbc_decrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def aes_cbc_decrypt(cipher_text: bytes, iv: bytes, key: bytes):
        cipher = AES.new(key=key, mode=AES.MODE_CBC, iv=iv)
        return unpad(cipher.decrypt(cipher_text), AES.block_size, style='pkcs7') 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:5,代码来源:aes_handler.py

示例6: test_aes_gcm_with_iv

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def test_aes_gcm_with_iv(self):
        key = b'Sixteen byte key'
        plain_text = b'Attack at dawn'
        hdr = b'To your eyes only'
        iv = Random.new().read(AES.block_size)
        mac, cipher_text = AESHandler.aes_gcm_encrypt_with_iv(plain_text, hdr, key, iv)
        decrypt_out = AESHandler.aes_gcm_decrypt_with_iv(cipher_text, hdr, mac, key, iv)
        self.assertEqual(plain_text, decrypt_out) 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:10,代码来源:test_aes_handler.py

示例7: test_aes_gcm_with_iv_wrong_iv

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def test_aes_gcm_with_iv_wrong_iv(self):
        key = b'Sixteen byte key'
        plain_text = b'Attack at dawn'
        hdr = b'To your eyes only'
        iv = Random.new().read(AES.block_size)
        mac, cipher_text = AESHandler.aes_gcm_encrypt_with_iv(plain_text, hdr, key, iv)
        iv = Random.new().read(AES.block_size)
        decrypt_out = AESHandler.aes_gcm_decrypt_with_iv(cipher_text, hdr, mac, key, iv)
        self.assertNotEqual(plain_text, decrypt_out) 
开发者ID:ontio,项目名称:ontology-python-sdk,代码行数:11,代码来源:test_aes_handler.py

示例8: create_key

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def create_key():
        return b64encode(os.urandom(AES.block_size)).decode() 
开发者ID:namuyan,项目名称:p2p-python,代码行数:4,代码来源:utils.py

示例9: is_aes_key

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def is_aes_key(key):
        try:
            return len(b64decode(key.encode())) == AES.block_size
        except Exception as e:
            return False 
开发者ID:namuyan,项目名称:p2p-python,代码行数:7,代码来源:utils.py

示例10: encrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def encrypt(key, raw):
        assert type(raw) == bytes, "input data is bytes"
        if isinstance(key, str):
            key = b64decode(key.encode())
        raw = pad(raw, AES.block_size)
        iv = Random.new().read(AES.block_size)
        cipher = AES.new(key, AES.MODE_CBC, iv)
        return iv + cipher.encrypt(raw) 
开发者ID:namuyan,项目名称:p2p-python,代码行数:10,代码来源:utils.py

示例11: decrypt

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def decrypt(key, enc):
        assert type(enc) == bytes, 'Encrypt data is bytes'
        if isinstance(key, str):
            key = b64decode(key.encode())
        iv = enc[:AES.block_size]
        cipher = AES.new(key, AES.MODE_CBC, iv)
        raw = cipher.decrypt(enc[AES.block_size:])
        raw = unpad(raw, AES.block_size)
        if len(raw) == 0:
            raise ValueError("AES decryption error, not correct key.")
        return raw 
开发者ID:namuyan,项目名称:p2p-python,代码行数:13,代码来源:utils.py

示例12: test_building_with_supported_cipher_sets_lengths

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def test_building_with_supported_cipher_sets_lengths(self):
        # RSA_WITH_AES_128_CBC_SHA
        cipher_suite = 0x2f
        sec_params = tlsc.TLSSecurityParameters.from_pre_master_secret(self.prf, cipher_suite, self.pre_master_secret,
                                                                       self.client_random, self.server_random)
        self.assertEqual(sec_params.cipher_key_length, 16)
        self.assertEqual(sec_params.mac_key_length, SHA.digest_size)
        self.assertEqual(sec_params.iv_length, AES.block_size) 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:10,代码来源:test_ssl_tls_crypto.py

示例13: test_building_with_null_cipher_sets_lengths

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def test_building_with_null_cipher_sets_lengths(self):
        # RSA_WITH_NULL_MD5
        cipher_suite = 0x1
        sec_params = tlsc.TLSSecurityParameters.from_pre_master_secret(self.prf, cipher_suite, self.pre_master_secret,
                                                                       self.client_random, self.server_random)
        self.assertEqual(sec_params.cipher_key_length, 0)
        self.assertEqual(sec_params.mac_key_length, MD5.digest_size)
        self.assertEqual(sec_params.iv_length, tlsc.NullCipher.block_size) 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:10,代码来源:test_ssl_tls_crypto.py

示例14: test_cbc_cipher_payload_is_block_size_aligned

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def test_cbc_cipher_payload_is_block_size_aligned(self):
        data = b"A" * 1025
        crypto_data = tlsc.CryptoData.from_context(self.tls_ctx, self.tls_ctx.client_ctx, data)
        crypto_container = tlsc.CBCCryptoContainer.from_context(self.tls_ctx, self.tls_ctx.client_ctx, crypto_data)
        self.assertTrue(len(crypto_container) % AES.block_size == 0) 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:7,代码来源:test_ssl_tls_crypto.py

示例15: test_tls_1_1_and_above_has_a_random_explicit_iv_with_block_cipher

# 需要导入模块: from Cryptodome.Cipher import AES [as 别名]
# 或者: from Cryptodome.Cipher.AES import block_size [as 别名]
def test_tls_1_1_and_above_has_a_random_explicit_iv_with_block_cipher(self):
        data = b"C" * 102
        self._do_kex(tls.TLSVersion.TLS_1_1)
        crypto_container = tlsc.CBCCryptoContainer.from_data(self.tls_ctx, self.tls_ctx.server_ctx, data)
        self.assertNotEqual(crypto_container.explicit_iv, b"")
        self.assertEqual(len(crypto_container.explicit_iv), AES.block_size)
        self.assertTrue(str(crypto_container).startswith(crypto_container.explicit_iv)) 
开发者ID:tintinweb,项目名称:scapy-ssl_tls,代码行数:9,代码来源:test_ssl_tls_crypto.py


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