最近在弄一个系统的登录,登录前端代码如下:
decryptSecret(modulus, publicExponent, word) {
const rsa = new JSEncrypt().getKey()
rsa.setPublic(modulus, publicExponent)
const result = rsa.encrypt(word)
return result
}
前端代码是对模指和模数加密,如何对密码进行加密处理,代码如下:
import rsa
def get_code(userName="xxx", password="xxx"):
url = 'xxx'
data = 'sn={0}'.format(userName)
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
ret = requests.post(url=url, data=data, headers=headers, cookies=cookies, verify=False)
modulus = json.loads(ret.text)['data']['data']['modulus']
public_exponent = json.loads(ret.text)['data']['data']['public_exponent']
# 对模指处理为16进制
e = int(public_exponent, 16)
# 对模数处理为16进制
n = int(modulus, 16)
pub_key = rsa.PublicKey(e=e, n=n)
m = rsa.encrypt(password.encode(), pub_key)
print(m.hex())
url1 = "xxx
params = {
"sn": userName,
"password": m.hex(),
"challenge": "",
}
resp = requests.post(url, data=params, verify=False)