Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

t_crypt.py 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #
  2. # Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import base64
  17. import os
  18. import sys
  19. from Cryptodome.PublicKey import RSA
  20. from Cryptodome.Cipher import PKCS1_v1_5 as Cipher_pkcs1_v1_5
  21. from api.utils import decrypt, file_utils
  22. def crypt(line):
  23. file_path = os.path.join(
  24. file_utils.get_project_base_directory(),
  25. "conf",
  26. "public.pem")
  27. rsa_key = RSA.importKey(open(file_path).read(),"Welcome")
  28. cipher = Cipher_pkcs1_v1_5.new(rsa_key)
  29. password_base64 = base64.b64encode(line.encode('utf-8')).decode("utf-8")
  30. encrypted_password = cipher.encrypt(password_base64.encode())
  31. return base64.b64encode(encrypted_password).decode('utf-8')
  32. if __name__ == "__main__":
  33. passwd = crypt(sys.argv[1])
  34. print(passwd)
  35. print(decrypt(passwd))