Skip to content

Commit

Permalink
chore : added iv as an argument inside encryptionutil
Browse files Browse the repository at this point in the history
  • Loading branch information
shahumang19 committed Jun 12, 2023
1 parent eb82338 commit 028387d
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/util/encryptionutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,22 @@


class EncryptionUtil:
IV = b'\x00' * 16

@staticmethod
def aes_encrypt_from_base64(clear_text, key_base64):
def aes_encrypt_from_base64(clear_text, key_base64, iv=b'\x00' * 16):
# clear_text = clear_text.encode('utf-8')
key = base64.b64decode(key_base64)
cipher = Cipher(algorithms.AES(key), modes.CTR(EncryptionUtil.IV), backend=default_backend())
cipher = Cipher(algorithms.AES(key), modes.CTR(iv), backend=default_backend())
encryptor = cipher.encryptor()
padder = padding.PKCS7(algorithms.AES.block_size).padder()
padded_plaintext = padder.update(clear_text) + padder.finalize()
cipher_text = encryptor.update(padded_plaintext) + encryptor.finalize()
return base64.b64encode(cipher_text).decode()

@staticmethod
def aes_decrypt_from_base64(encrypted_text, self_encryption_key):
def aes_decrypt_from_base64(encrypted_text, self_encryption_key, iv=b'\x00' * 16):
cipher_text = base64.b64decode(encrypted_text)
key = base64.b64decode(self_encryption_key)
cipher = Cipher(algorithms.AES(key), modes.CTR(EncryptionUtil.IV), backend=default_backend())
cipher = Cipher(algorithms.AES(key), modes.CTR(iv), backend=default_backend())
decryptor = cipher.decryptor()
plain_text = decryptor.update(cipher_text) + decryptor.finalize()

Expand Down

0 comments on commit 028387d

Please sign in to comment.