當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。