uniapp,vue3 vite
jsencrypts.js在微信小程序iOS下rsa解密,URLEncoder转码慢的问题.
加密内容是长内容,里面有中文字符,符号等,防止前端乱码,后端先转encodeurl编码,然后用再将内容rsa加密输出给前端.(rsa公 私钥用的512)
后端代码:
public static String encrypt(String content, String publicKey) {
try {
RSA rsa = new RSA(null, publicKey);
content=URLEncoder.encode(content,"UTF-8");
System.out.println("-------------------------------"+content);
String ss = rsa.encryptBase64(content, KeyType.PublicKey);
return ss;
} catch (Exception e) {
log.error("公钥加密异常 msg:{}",e.getMessage());
}
return null;
前端用jsencrypts.js解密,由于长内容,用的decryptLong方法,64字符分段解密, var MAX_DECRYPT_BLOCK = 64
前端再用decodeURIComponent转回中文字符,
分段解密时decryptLong会在方法里面去调decrypt方法,decrypt返回时间较慢。求问如何优化解码时间太长的问题
但是ios小程序解得很慢,约延迟8s+,定位下来,(h5,小程序安卓机速度都正常)
求问如何优化解码时间太长的问题
已尝试方法:换wxmp-rsa 解密,也是一样的效果,现如何解决ios解码慢的问题?
export function decrypt (s) {
// Return the decrypted string.
try {
var ret = "";
var i;
var k = 0; // b64 state, 0-3
var slop = 0;
for (i = 0; i < s.length; ++i) {
if (s.charAt(i) == b64pad) {
break;
}
var v = b64map.indexOf(s.charAt(i));
if (v < 0) {
continue;
}
if (k == 0) {
ret += int2char(v >> 2);
slop = v & 3;
k = 1;
}
else if (k == 1) {
ret += int2char((slop << 2) | (v >> 4));
slop = v & 0xf;
k = 2;
}
else if (k == 2) {
ret += int2char(slop);
ret += int2char(v >> 2);
slop = v & 3;
k = 3;
}
else {
ret += int2char((slop << 2) | (v >> 4));
ret += int2char(v & 0xf);
k = 0;
}
}
if (k == 1) {
ret += int2char(slop << 2);
}
return this.getKey().decrypt(ret);
}
catch (ex) {
return false;
}
};