secret_encryption.py 471 B

1234567891011121314151617181920
  1. import Crypto
  2. import hashlib
  3. import os
  4. class secret_crypto:
  5. def __init__(self, password: str):
  6. self.__iv = os.urandom(16)
  7. self.__key = self.__create_key(password)
  8. @property
  9. def __cipher(self) -> Crypto.Cipher:
  10. return Crypto.Cipher.AES.new(self.__key
  11. def __create_key(self, password: str) -> bytes:
  12. encoded = password.encode("UTF-8")
  13. hashed = hashlib.sha256(encoded)
  14. return hashed.digest()