RSAKey.prototype.decryptBin = RSADecryptBin; /** * @description decrypt bytearray * @param ba target data */ functionRSADecryptBin(ba) { let c = new BigInteger(ba); var m = this.doPrivate(c); if(m == null) returnnull; return pkcs1unpad2(m, (this.n.bitLength()+7)>>3); };
JSEncrypt.prototype.decryptBin = function (ba) { // Return the decrypted string. try { returnthis.getKey().decryptBin(ba); } catch (ex) { returnfalse; } };
另外添加一下socket的数据接受:
1 2 3 4 5 6 7 8 9 10 11 12 13
var rsaUtil = { ... decryptBin : function (ciphered) { // privatekey && rsaUtil.thisKeyPair.setPrivateKey(privatekey); let decstring = rsaUtil.thisKeyPair.decryptBin(ciphered); return decstring; } }
socket.on('data',(data)=>{ let result = rsaUtil.decryptBin(data); console.log(result); });