Mercurial > libervia-backend
comparison libervia/backend/memory/crypto.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
55 else BlockCipher.pad(key) | 55 else BlockCipher.pad(key) |
56 ) | 56 ) |
57 | 57 |
58 cipher = Cipher(algorithms.AES(key), modes.CFB8(iv), backend=crypto_backend) | 58 cipher = Cipher(algorithms.AES(key), modes.CFB8(iv), backend=crypto_backend) |
59 encryptor = cipher.encryptor() | 59 encryptor = cipher.encryptor() |
60 encrypted = encryptor.update(BlockCipher.pad(text.encode())) + encryptor.finalize() | 60 encrypted = ( |
61 encryptor.update(BlockCipher.pad(text.encode())) + encryptor.finalize() | |
62 ) | |
61 return b64encode(iv + encrypted).decode() | 63 return b64encode(iv + encrypted).decode() |
62 | 64 |
63 @staticmethod | 65 @staticmethod |
64 def decrypt(key, ciphertext, leave_empty=True): | 66 def decrypt(key, ciphertext, leave_empty=True): |
65 """Decrypt a message. | 67 """Decrypt a message. |
147 # and must be changed as soon as possible | 149 # and must be changed as soon as possible |
148 algorithm=hashes.SHA1(), | 150 algorithm=hashes.SHA1(), |
149 length=16, | 151 length=16, |
150 salt=salt, | 152 salt=salt, |
151 iterations=1000, | 153 iterations=1000, |
152 backend=crypto_backend | 154 backend=crypto_backend, |
153 ) | 155 ) |
154 key = kdf.derive(password.encode()) | 156 key = kdf.derive(password.encode()) |
155 return b64encode(salt + key).decode() | 157 return b64encode(salt + key).decode() |
156 | 158 |
157 @staticmethod | 159 @staticmethod |