Я пытаюсь запустить следующий фрагмент в python2 .7 (key
переменная уже установлена):
import binascii
from Crypto.Cipher import AES
iv = binascii.unhexlify(u'd75b8c8b8c8bc1add8f8fcc1add8f8fc')
AES.new(key, AES.MODE_CFB, iv)
Появляется следующее исключение:
Error:
raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <type 'unicode'> cannot be passed to C code
Согласно binascii docs :
Return the binary data represented by the hexadecimal string hexstr. This function is the inverse of b2a_hex(). hexstr must contain an even number of hexadecimal digits (which can be upper or lower case), otherwise a TypeError is raised.
И pycryptodome docs :
iv (bytes, bytearray, memoryview) – (Only applicable for MODE_CBC, MODE_CFB, MODE_OFB, and MODE_OPENPGP modes).
The initialization vector to use for encryption or decryption.
For MODE_CBC, MODE_CFB, and MODE_OFB it must be 16 bytes long.
For MODE_OPENPGP mode only, it must be 16 bytes long for encryption and 18 bytes for decryption (in the latter case, it is actually the encrypted IV which was prefixed to the ciphertext).
If not provided, a random byte string is generated (you must then read its value with the iv attribute).
Переменная iv
имеет даже по длине, так почему возникает ошибка TypeError?