Объект 'dict' не имеет атрибута 'encode' в AES django
Итак, я хочу зашифровать файл, используя ключ, который я ввел. но есть сообщение об ошибке:
у объекта 'dict' нет атрибута 'encode'
и строка, которая выдает такую ошибку. Я уже читал на другом сайте, что нужно добавить encode('utf8'), но у меня это не работает. Я скопировал код с помощью этого by tweaksp
aes = AES.new(key.encode('utf8'), AES.MODE_CTR, counter=ctr.encode('utf8'))
Если вам нужен полный код, то вот:
# AES supports multiple key sizes: 16 (AES128), 24 (AES192), or 32 (AES256).
key_bytes = 16
# Takes as input a 32-byte key and an arbitrary-length plaintext and returns a
# pair (iv, ciphtertext). "iv" stands for initialization vector.
def encrypt(key, testpass):
assert len(key) == key_bytes
print(testpass)
print(key)
# Choose a random, 16-byte IV.
iv = Random.new().read(AES.block_size)
# Convert the IV to a Python integer.
iv_int = int(binascii.hexlify(iv), 16)
# Create a new Counter object with IV = iv_int.
ctr = Counter.new(AES.block_size * 8, initial_value=iv_int)
# Create AES-CTR cipher.
aes = AES.new(key.encode('utf8'), AES.MODE_CTR, counter=ctr.encode('utf8'))
# Encrypt and return IV and ciphertext.
ciphertext = aes.encrypt(testpass)
print(iv)
print(ciphertext)
return (iv, ciphertext)
я вызвал эту функцию следующим образом
enkripsi = encrypt("testingtesting11", testpass)