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