Je compare les implémentations AES en Python à partir des bibliothèques pycrypto et cryptography.io.Différences d'implémentation AES Python
from cryptography.hazmat.primitives.ciphers import Cipher, modes, algorithms
from cryptography.hazmat.backends import default_backend # http://cryptography.io
from Crypto.Cipher import AES # http://pycrypto.org
key = b'Sixteen byte key'
iv = b'Sixteen byte ivv'
cipher1 = AES.new(key, AES.MODE_CFB, iv)
cipher2 = Cipher(algorithms.AES(key), modes.CFB(iv), default_backend())
plaintext = b"Plaintext"
print(cipher1.encrypt(plaintext))
print(cipher1.decrypt(plaintext))
print(cipher2.encryptor().update(plaintext))
print(cipher2.decryptor().update(plaintext))
Les impressions MWE:
b'\xe4\xb4\xeb\xe3Si\x9ap\xee'
b'7\xda\x98\xee\x05\xe4\xa0\xc7,'
b'\xe4"\xd4mo\xa3;\xa9\xe0'
b'\xe4"\xd4mo\xa3;\xa9\xe0'
Pourquoi les sorties différentes?
Peut-être que vous voulez dire CFB-8? Le comportement par défaut de CFB PyCrypto est décrit [ici] (https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.AES-module.html#new): 'segment_size (entier) - (Seulement MODE_CFB) .Le nombre de bits dans lesquels le texte en clair et le texte chiffré sont segmentés. Il doit être un multiple de 8. Si 0 ou non spécifié, il sera supposé être 8. ' – SquareRootOfTwentyThree
@SquareRootOfTwentyThree Oui en effet, corrigé. –