secret_util.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """
  2. 密码标签生成与验证功能
  3. """
  4. import random
  5. import string
  6. import secrets
  7. # 模拟256长度的十六进制字符串
  8. mock_secret_key = '921999081bdd6fe50d3a5700e714915c31458929647e1d115bf180024cb67f7b337824246b8f74b0eeff021d5631ea9a1ec118297d759d01165eeabe4ee5d02519118ecc7d4d6bef43af09b5956b0adf92adcf99186a05a2f160c3071345a7093bc0cb476f9313db3330471cd764ddfeccd22d3fa090ecdd98cc4c0c083173e6'
  9. mock_secret_key_50 = '6e887a550f5ba6a7733ec341f1692027936895ca4041a50828'
  10. mock_secret_key_20 = '08b9dc4ab8f22541588a'
  11. mock_secret_key_512 = '0ba32b797dba3243c46840b224986f60e00526e5dda92891812a449ae23f24ed0cc38d860bec0af7b5359dc795fd1b8c5e9d24a4da4a7091ce0ea25913c21c66239b5352f138dc22349f49e6a47509dc07a30702d26c86885a5470fc2c659428c098daeb69c809dbe48739ae152b7d728eedbb2a02c213803cdf1218c9006801b4f566ca385e3752d6a825052191d518113c29055308ed1b815a7da88997babcd44cfd812ac7f75ff9e380c507e26e997a5849710104bea371955641b68a4f01ba0eabf4d425df9d123c2b1ab357599f3eb9070028f4e7f6ae60d0c060dacbf2f21e058dfb9adb4004dc4ae8d0c72f8bcc4ce7f604cf8919c1108796ab4571a3'
  12. def get_secret(len):
  13. """
  14. 获取密码标签
  15. :param len: 标签长度
  16. :return: 生成的密码标签
  17. """
  18. return mock_secret_key_512
  19. def verify_secret(secret):
  20. """
  21. 验证密码标签
  22. :param secret: 密码标签
  23. :return: 验证结果
  24. """
  25. return secret == mock_secret_key_512
  26. def generate_random_string(length):
  27. """生成指定长度的随机字符串"""
  28. return ''.join(random.choices(string.ascii_letters + string.digits, k=length))
  29. def generate_hex_string(length):
  30. return ''.join(secrets.choice('0123456789abcdef') for _ in range(length))