本文整理匯總了Python中Cryptodome.Cipher.AES.MODE_ECB屬性的典型用法代碼示例。如果您正苦於以下問題:Python AES.MODE_ECB屬性的具體用法?Python AES.MODE_ECB怎麽用?Python AES.MODE_ECB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類Cryptodome.Cipher.AES
的用法示例。
在下文中一共展示了AES.MODE_ECB屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: decode_aes256
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decode_aes256(cipher, iv, data, encryption_key):
"""
Decrypt AES-256 bytes.
Allowed ciphers are: :ecb, :cbc.
If for :ecb iv is not used and should be set to "".
"""
if cipher == 'cbc':
aes = AES.new(encryption_key, AES.MODE_CBC, iv)
elif cipher == 'ecb':
aes = AES.new(encryption_key, AES.MODE_ECB)
else:
raise ValueError('Unknown AES mode')
d = aes.decrypt(data)
# http://passingcuriosity.com/2009/aes-encryption-in-python-with-m2crypto/
unpad = lambda s: s[0:-ord(d[-1:])]
return unpad(d)
示例2: decryptSecret
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decryptSecret(key, value):
# [MS-LSAD] Section 5.1.2
plainText = b''
key0 = key
for i in range(0, len(value), 8):
cipherText = value[:8]
tmpStrKey = key0[:7]
tmpKey = transformKey(tmpStrKey)
Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
plainText += Crypt1.decrypt(cipherText)
key0 = key0[7:]
value = value[8:]
# AdvanceKey
if len(key0) < 7:
key0 = key[len(key0):]
secret = LSA_SECRET_XP(plainText)
return (secret['Secret'])
示例3: encryptSecret
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def encryptSecret(key, value):
# [MS-LSAD] Section 5.1.2
cipherText = b''
key0 = key
value0 = pack('<LL', len(value), 1) + value
for i in range(0, len(value0), 8):
if len(value0) < 8:
value0 = value0 + b'\x00'*(8-len(value0))
plainText = value0[:8]
tmpStrKey = key0[:7]
print(type(tmpStrKey))
print(tmpStrKey)
tmpKey = transformKey(tmpStrKey)
Crypt1 = DES.new(tmpKey, DES.MODE_ECB)
cipherText += Crypt1.encrypt(plainText)
key0 = key0[7:]
value0 = value0[8:]
# AdvanceKey
if len(key0) < 7:
key0 = key[len(key0):]
return cipherText
示例4: SamDecryptNTLMHash
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def SamDecryptNTLMHash(encryptedHash, key):
# [MS-SAMR] Section 2.2.11.1.1
Block1 = encryptedHash[:8]
Block2 = encryptedHash[8:]
Key1 = key[:7]
Key1 = transformKey(Key1)
Key2 = key[7:14]
Key2 = transformKey(Key2)
Crypt1 = DES.new(Key1, DES.MODE_ECB)
Crypt2 = DES.new(Key2, DES.MODE_ECB)
plain1 = Crypt1.decrypt(Block1)
plain2 = Crypt2.decrypt(Block2)
return plain1 + plain2
示例5: SamEncryptNTLMHash
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def SamEncryptNTLMHash(encryptedHash, key):
# [MS-SAMR] Section 2.2.11.1.1
Block1 = encryptedHash[:8]
Block2 = encryptedHash[8:]
Key1 = key[:7]
Key1 = transformKey(Key1)
Key2 = key[7:14]
Key2 = transformKey(Key2)
Crypt1 = DES.new(Key1, DES.MODE_ECB)
Crypt2 = DES.new(Key2, DES.MODE_ECB)
plain1 = Crypt1.encrypt(Block1)
plain2 = Crypt2.encrypt(Block2)
return plain1 + plain2
示例6: decryptData
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decryptData(key, encryptedData):
"""Decrypts the apk data using the specified AES key"""
aes = AES.new(key, AES.MODE_ECB)
return b''.join(util.unpad(aes.decrypt(c)) for c in util.chunk(encryptedData, constants.blockSize + constants.paddingSize))
示例7: encryptData
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def encryptData(key, data):
"""Encrypts the apk data using the specified AES key"""
aes = AES.new(key, AES.MODE_ECB)
return b''.join(aes.encrypt(util.pad(c, constants.paddingSize)) for c in util.chunk(data, constants.blockSize))
示例8: symmetric_encrypt_ecb
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_encrypt_ecb(message, key):
return AES.new(key, AES.MODE_ECB).encrypt(pad(message))
示例9: symmetric_encrypt_iv
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_encrypt_iv(iv, key):
return AES.new(key, AES.MODE_ECB).encrypt(iv)
示例10: symmetric_decrypt_ecb
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_decrypt_ecb(cyphertext, key):
return unpad(AES.new(key, AES.MODE_ECB).decrypt(cyphertext))
示例11: symmetric_decrypt_iv
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def symmetric_decrypt_iv(cyphertext, key):
return AES.new(key, AES.MODE_ECB).decrypt(cyphertext[:BS])
示例12: __init__
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def __init__(self, key):
super(AesCrypter, self).__init__(1024)
self._cipher = AES.new(key, AES.MODE_ECB)
示例13: aes_kdf
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def aes_kdf(key, rounds, key_composite):
"""Set up a context for AES128-ECB encryption to find transformed_key"""
cipher = AES.new(key, AES.MODE_ECB)
# get the number of rounds from the header and transform the key_composite
transformed_key = key_composite
for _ in range(0, rounds):
transformed_key = cipher.encrypt(transformed_key)
return hashlib.sha256(transformed_key).digest()
示例14: encrypt
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def encrypt(privkey, passphrase):
""" BIP0038 non-ec-multiply encryption. Returns BIP0038 encrypted privkey.
:param privkey: Private key
:type privkey: Base58
:param str passphrase: UTF-8 encoded passphrase for encryption
:return: BIP0038 non-ec-multiply encrypted wif key
:rtype: Base58
"""
if isinstance(privkey, str):
privkey = PrivateKey(privkey)
else:
privkey = PrivateKey(repr(privkey))
privkeyhex = repr(privkey) # hex
addr = format(privkey.bitcoin.address, "BTC")
a = _bytes(addr)
salt = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4]
if SCRYPT_MODULE == "scrypt": # pragma: no cover
key = scrypt.hash(passphrase, salt, 16384, 8, 8)
elif SCRYPT_MODULE == "pylibscrypt": # pragma: no cover
key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8)
else: # pragma: no cover
raise ValueError("No scrypt module loaded") # pragma: no cover
(derived_half1, derived_half2) = (key[:32], key[32:])
aes = AES.new(derived_half2, AES.MODE_ECB)
encrypted_half1 = _encrypt_xor(privkeyhex[:32], derived_half1[:16], aes)
encrypted_half2 = _encrypt_xor(privkeyhex[32:], derived_half1[16:], aes)
" flag byte is forced 0xc0 because Graphene only uses compressed keys "
payload = b"\x01" + b"\x42" + b"\xc0" + salt + encrypted_half1 + encrypted_half2
" Checksum "
checksum = hashlib.sha256(hashlib.sha256(payload).digest()).digest()[:4]
privatkey = hexlify(payload + checksum).decode("ascii")
return Base58(privatkey)
示例15: decrypt_file
# 需要導入模塊: from Cryptodome.Cipher import AES [as 別名]
# 或者: from Cryptodome.Cipher.AES import MODE_ECB [as 別名]
def decrypt_file(metadata, encryption_material, in_filename,
chunk_size=block_size * 4 * 1024, tmp_dir=None):
"""Decrypts a file and stores the output in the temporary directory.
Args:
metadata: The file's metadata input.
encryption_material: The file's encryption material.
in_filename: The name of the input file.
chunk_size: The size of read chunks (Default value = block_size * 4 * 1024).
tmp_dir: Temporary directory to use, optional (Default value = None).
Returns:
The decrypted file's location.
"""
logger = getLogger(__name__)
use_openssl_only = os.getenv('SF_USE_OPENSSL_ONLY', 'False') == 'True'
key_base64 = metadata.key
iv_base64 = metadata.iv
decoded_key = base64.standard_b64decode(
encryption_material.query_stage_master_key)
key_bytes = base64.standard_b64decode(key_base64)
iv_bytes = base64.standard_b64decode(iv_base64)
if not use_openssl_only:
key_cipher = AES.new(key=decoded_key, mode=AES.MODE_ECB)
file_key = PKCS5_UNPAD(key_cipher.decrypt(key_bytes))
data_cipher = AES.new(key=file_key, mode=AES.MODE_CBC, IV=iv_bytes)
else:
backend = default_backend()
cipher = Cipher(algorithms.AES(decoded_key), modes.ECB(), backend=backend)
decryptor = cipher.decryptor()
file_key = PKCS5_UNPAD(decryptor.update(key_bytes) + decryptor.finalize())
cipher = Cipher(algorithms.AES(file_key), modes.CBC(iv_bytes), backend=backend)
decryptor = cipher.decryptor()
temp_output_fd, temp_output_file = tempfile.mkstemp(
text=False, dir=tmp_dir,
prefix=os.path.basename(in_filename) + "#")
total_file_size = 0
prev_chunk = None
logger.debug('encrypted file: %s, tmp file: %s',
in_filename, temp_output_file)
with open(in_filename, 'rb') as infile:
with os.fdopen(temp_output_fd, 'wb') as outfile:
while True:
chunk = infile.read(chunk_size)
if len(chunk) == 0:
break
total_file_size += len(chunk)
if not use_openssl_only:
d = data_cipher.decrypt(chunk)
else:
d = decryptor.update(chunk)
outfile.write(d)
prev_chunk = d
if prev_chunk is not None:
total_file_size -= PKCS5_OFFSET(prev_chunk)
if use_openssl_only:
outfile.write(decryptor.finalize())
outfile.truncate(total_file_size)
return temp_output_file