You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

t_crypt.py 725B

123456789101112131415161718192021222324
  1. import base64
  2. import os
  3. import sys
  4. from Cryptodome.PublicKey import RSA
  5. from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
  6. from api.utils import decrypt, file_utils
  7. def crypt(line):
  8. file_path = os.path.join(
  9. file_utils.get_project_base_directory(),
  10. "conf",
  11. "public.pem")
  12. rsa_key = RSA.importKey(open(file_path).read(),"Welcome")
  13. cipher = Cipher_pkcs1_v1_5.new(rsa_key)
  14. password_base64 = base64.b64encode(line.encode('utf-8')).decode("utf-8")
  15. encrypted_password = cipher.encrypt(password_base64.encode())
  16. return base64.b64encode(encrypted_password).decode('utf-8')
  17. if __name__ == "__main__":
  18. pswd = crypt(sys.argv[1])
  19. print(pswd)
  20. print(decrypt(pswd))