爬虫 密码加密之JSEncrypt

 

##加密

function setEncrypt(pwd) {
    var jsencrypt = new JSEncrypt(); // 新建JSEncrypt对象
    jsencrypt.setPublicKey(publicKey);// 设置公钥
    return jsencrypt.encrypt(pwd);// 对需要加密的数据进行加密
}

 

## python模拟

import base64
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
from Crypto.PublicKey import RSA

def encrpt(password, public_key):
    rsakey = RSA.importKey(public_key)
    cipher = Cipher_pksc1_v1_5.new(rsakey)
    cipher_text = base64.b64encode(cipher.encrypt(password.encode()))
    return cipher_text.decode()

# key是公钥,需要修改成自己的之后再进行加密
key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCC//WCWUQiDiIh8GhQfEwfU9OM7khBwlXE1HGEoBNakQJcr7iUPBUPADoik8d55z4KWCMgeImV+GHjGY/h8Vpy4nZ2AqmNlbz7MAtq9ln4p4EtgAvTqA8RFxV7SORd/GYio+mPh80T+zQJJwKpkxT1uewbU9LrSbqbkEtYpg9u2QIDAQAB'
public_key = '-----BEGIN PUBLIC KEY-----\n' + key + '\n-----END PUBLIC KEY-----'
password = encrpt('my_passwd', public_key)
print('password:', password)

 

posted on 2022-06-23 14:47  小单的书屋  阅读(122)  评论(0编辑  收藏  举报