1、修改源码,搜索:"t.prototype.getPublicKey = function(", 在后面接着加3个函数
(t.prototype.encryptLong = function(data) {
const text = this.encode2Unicode(data);
const akey = this.key;
const maxLength = ((akey.n.bitLength() + 7) >> 3) - 11;
try {
const arr = [];
if (text.length > maxLength) {
const matchResult = text.match(/.{1,117}/g);
matchResult.forEach(function (entry) {
const temp = akey.encrypt(entry);
arr.push(temp);
});
return this.hex2b64(arr.join(""));
} else {
let t = akey.encrypt(text);
return this.hex2b64(t);
}
} catch (ex) {
return false;
}
}),
(t.prototype.encode2Unicode = function(text) {
if (text == null) {
return "";
}
const newText = [];
for (var i = 0; i < text.length; i++) {
var code = text.charCodeAt(i);
if (code >= 128) {
//91 is "[", 93 is "]".
newText.push("\\u" + code.toString(16));
} else {
newText.push(text.charAt(i));
}
}
return newText.join('');
}),
(t.prototype.hex2b64 = function(h) {
var b64map =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var b64pad = "=";
var i;
var c;
var ret = "";
for (i = 0; i + 3 <= h.length; i += 3) {
c = parseInt(h.substring(i, i + 3), 16);
ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
}
if (i + 1 == h.length) {
c = parseInt(h.substring(i, i + 1), 16);
ret += b64map.charAt(c << 2);
} else if (i + 2 == h.length) {
c = parseInt(h.substring(i, i + 2), 16);
ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
}
while ((ret.length & 3) > 0) ret += b64pad;
return ret;
}),
2、前端用pubulicKey加密 ,后端用privateKey解密
const publicKey = '';
const ins = new JSEncrypt();
ins.setPublicKey(publicKey);
return ins.encryptLong(text);