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 579B

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