javascript RSA公钥加密

PC端:

引入js

 

使用:

const PUBLIC_KEY =
    '-----BEGIN PUBLIC KEY-----\
    MIIBIjAvpvRqhkiG9w0BAQEFAAOCAQ8AMII\
    BCgKCAQEAz0LFPPBZYkV/d9mkM1Zmuv3lwgy\
    -----END PUBLIC KEY-----';

var encrypt = new JSEncrypt();
encrypt.setPublicKey(PUBLIC_KEY);
var encryptData = encrypt.encrypt("data");   //data必须转成字符串

微信小程序:

js Github链接:https://github.com/UFO0001/WX_RSA
用法:

var data= this.data;    
var encrypt_rsa = new RSA.RSAKey();   
encrypt_rsa = RSA.KEYUTIL.getKey(PUBLIC_KEY);   
encStr = encrypt_rsa.encrypt(data)   
encStr = RSA.hex2b64(encStr);   
console.log("加密结果:" + encStr)

你可能感兴趣的:(javascript RSA公钥加密)