encryDownLoad.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # coding=utf-8
  2. # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +
  3. # ┏┓   ┏┓+ +
  4. #    ┏┛┻━━━┛┻┓ + +
  5. #    ┃       ┃  
  6. #    ┃   ━   ┃ ++ + + +
  7. #    ████━████ ┃+
  8. #    ┃       ┃ +
  9. #    ┃   ┻   ┃
  10. #    ┃       ┃ + +
  11. #    ┗━┓   ┏━┛
  12. #      ┃   ┃           
  13. #      ┃   ┃ + + + +
  14. #      ┃   ┃    Codes are far away from bugs with the animal protecting   
  15. #      ┃   ┃ +     神兽保佑,代码无bug  
  16. #      ┃   ┃
  17. #      ┃   ┃  +         
  18. #      ┃    ┗━━━┓ + +
  19. #      ┃        ┣┓
  20. #      ┃        ┏┛
  21. #      ┗┓┓┏━┳┓┏┛ + + + +
  22. #       ┃┫┫ ┃┫┫
  23. #       ┗┻┛ ┗┻┛+ + + +
  24. # + + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + ++ + + +"""
  25. """
  26. """
  27. import base64
  28. import hashlib
  29. import time
  30. def md5(text, isBackByte=False):
  31. """md5加密函数"""
  32. md5 = hashlib.md5()
  33. if isinstance(text, bytes):
  34. md5.update(text)
  35. else:
  36. md5.update(text.encode('utf-8'))
  37. if isBackByte:
  38. # 返回二进制的加密结果
  39. return md5.digest()
  40. # 返回十六进制的机密结果
  41. return md5.hexdigest()
  42. def base64_encode(text, isBytes=False):
  43. """进行base64编码处理"""
  44. if isBytes:
  45. return base64.b64encode(text)
  46. return base64.b64encode(bytes(text, encoding="utf-8"))
  47. def get_timestamp10():
  48. """获取当前时间长度为10位长度的时间戳"""
  49. return int(time.time())
  50. url = 'http://192.168.136.45:8077'
  51. secret = 'ansjer'; # 密钥--对应#st的哈希格式为 secret+url+e,e为时间戳单位s,url为请求地址
  52. path = '/OTA/downloads/IPC/18E2012008A/4.1.5/V4.1.5.18E2012008A.img' # 下载文件
  53. # 下载到期时间,time是当前时间,300表示300秒,也就是说从现在到300秒之内文件不过期
  54. expire = get_timestamp10() + 3600;
  55. res = md5(str(secret) + str(path) + str(expire), True)
  56. md5 = str(base64_encode(res, True))
  57. md5 = md5.replace('b\'', '').replace('\'', '').replace('+', '-').replace('/', '_').replace('=', '')
  58. print(url+path+'?' + 'st=' + str(md5) + '&e=' + str(expire))