一.node启动js公钥加密
var arguments = process.argv.splice(2);
var e = arguments[1];
var t = arguments[0];
var name = arguments[2];
var forge = require('node-forge');
var n = "-----BEGIN PUBLIC KEY-----" + e + "-----END PUBLIC KEY-----"
, r = forge.pki.publicKeyFromPem(n)
, o = r.encrypt(t);
var data = forge.util.encode64(o).toString();
console.log(data);
二.python公钥加密
import base64
import rsa
from Crypto.PublicKey import RSA
def encryptPassword(password, publicKeyStr):
'''
password:密码
publicKeyStr:公钥
'''
publicKeyBytes = base64.b64decode(publicKeyStr.encode())
key = RSA.import_key(publicKeyBytes)
encryptPassword = rsa.encrypt(password.encode(), key)
return base64.b64encode(encryptPassword).decode()