Just Trying to Encrypt the plain text using MultiFernet
.
My code is:
from cryptography.fernet import Fernet, MultiFernet
fetnet_keys = [
Fernet.generate_key(),
Fernet.generate_key()
]
mulfern = MultiFernet(fetnet_keys)
enc = mulfern.encrypt("My Message in Plain Text".encode('utf-8'))
print(enc)
When trying to encrypt the plain text I am getting:
Traceback (most recent call last):
File "encryption1.py", line 21, in <module>
enc = mulfern.encrypt("My Message in Plain Text".encode('utf-8'))
File "venv3.8\lib\site-packages\cryptography\fernet.py", line 169, in encrypt
return self.encrypt_at_time(msg, int(time.time()))
File "venv3.8\lib\site-packages\cryptography\fernet.py", line 172, in encrypt_at_time
return self._fernets[0].encrypt_at_time(msg, current_time)
AttributeError: 'bytes' object has no attribute 'encrypt_at_time'
What's the solution?
Fernet.generate_key()
returns abytes
object. That key should be used to initialize aFernet
object.MultiFernet()
takes a list ofFernet
objects. NoteMultiFernet
encrypts with the first key in the list, but decrypts by trying each key.Example:
Output: