登录接口,密码前端密码加密
1、rsa加密
# -*-coding:utf-8-*- import base64 from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_v1_5 as Encry # 公钥 public_key = """-----BEGIN PUBLIC KEY----- MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpCtF/Tb8RLg207RRMtSPMo2vdNePDO T853pcwG+WIUWP6QY1q4E+MQPBD64gnbsLpI1vBYJIfgFnau2Zuq6EI7ISMJwv9VWKuiq 6gFKbb+jOs5xxCRP04cmxk5AUrT0/8StrygmntEAynnIXkASO7Nai1DUmj6MQ9MQaJ/vY LuQIDAQAB -----END PUBLIC KEY-----""" pass_ward = str('') rsakey = RSA.importKey(public_key) cipher = Encry.new(rsakey) cipher_txt = base64.b64encode(cipher.encrypt(pass_ward)) print cipher_txt
2、密码与随机数做异或处理
# 原始密码 password = ‘123456’ # 生成加密随机数 num1 = int(1000 * random.random()) # 注意放在header中 n = '' for i in range(len(password)): # ord('A')函数获取 字母‘A’的ascii。然后和随机数异或。unichr(37)函数,是将该数字37再转化为ascii码 n += unichr(num1 ^ ord(password[i]))
# 这里做url处理。 例如:url中的 (=) 会变成 %2f。
assword = urllib.quote(n.encode('utf-8'))