RSAKey.prototype.decrypt = function (ctext){var c =parseBigInt(ctext,16);var m =this.doPublic(c);if(m ==null){returnnull;}returnpkcs1unpad2(m,(this.n.bitLength()+7)>>3);};
1
2
3
4
5
6
7
8
原:
新:
更改pkcs1unpad2方法,更换内容如下:
function pkcs1unpad2(d, n){var b = d.toByteArray()var i =0while(i < b.length && b[i]===0){++i
}// if (b.length - i !== n - 1 || b[i] !== 2) {// return null// }++i
while(b[i]!==0){if(++i >= b.length){returnnull}}var ret = ''
while(++i < b.length){var c = b[i]&255if(c <128){// utf-8 decode
ret +=String.fromCharCode(c)}elseif((c >191)&&(c <224)){
ret +=String.fromCharCode(((c &31)<<6)|(b[i +1]&63))++i
}else{
ret +=String.fromCharCode(((c &15)<<12)|((b[i +1]&63)<<6)|(b[i +2]&63))
i +=2}}return ret
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
原:
新:
3. 实际使用: import JSEncrypt from '@/utils/jsencrypt'