2025年3月31日 星期一 乙巳(蛇)年 正月初一 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 编程开发 > Python

Python爬虫加密即拿即用【Base64加密、解密】

时间:04-23来源:作者:点击数:42

Python爬虫加密即拿即用【Base64加密、解密】

  • """
  • base64加密
  • # 被编码的参数必须是二进制数据
  • Base64编码是一种“防君子不防小人”的编码方式。广泛应用于MIME协议,作为电子邮件的传输编码,生成的编码可逆,后一两位可能有“=”,生成的编码都是ascii字符。
  • 优点:速度快,ascii字符,肉眼不可理解
  • 缺点:编码比较长,非常容易被破解,仅适用于加密非关键信息的场合
  • """
  • import base64
  • s = 'what the help'
  • base64_s = 'd2hhdCB0aGUgaGVscA=='
  • def base64_encrypt(text):
  • text_format = text.encode("utf-8")
  • result = base64.b64encode(text_format).decode()
  • return result
  • def base64_decrypt(base64_text):
  • result = base64.b64decode(base64_text).decode("utf-8")
  • return result
  • base64_test = base64_encrypt(s)
  • print(base64_test) # d2hhdCB0aGUgaGVscA==
  • rebase64_test = base64_decrypt(base64_s)
  • print(rebase64_test) # what the help
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门