我正在玩 jsencrypt 并注意到一些非常奇怪的东西。这是我的代码。如果它们在变量中,则加密和解密工作。但是当我控制台记录 enc 然后将值复制到字符串中时,解密返回 null。有谁知道我做错了什么?
const crypt = new JSEncrypt();
crypt.setPublicKey = `-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCnL4SAkXXmeub2DccgTT4v9EQr
vkvqPQPzRPOeIL525tQd7vg1BlgxxnoS4oDn0G3JlzqI6y/VIaZy6QrIo3s5R2A9
IiymPkeVOih4V5QeNSAO8tmUbEX4uEFWQDyObMeyF44R7fUoyUCcC/WdKezwcJlg
q6dXIFJOyEzwJx0MPQIDAQAB
-----END PUBLIC KEY-----`;
crypt.setPrivateKey = `-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKcvhICRdeZ65vYN
xyBNPi/0RCu+S+o9A/NE854gvnbm1B3u+DUGWDHGehLigOfQbcmXOojrL9UhpnLp
CsijezlHYD0iLKY+R5U6KHhXlB41IA7y2ZRsRfi4QVZAPI5sx7IXjhHt9SjJQJwL
9Z0p7PBwmWCrp1cgUk7ITPAnHQw9AgMBAAECgYEAl4kAZrBx1wiLE3cFiAe7WCfl
Kmj/0j6ft/5FeoxfVtJ+bOtPWnB3vBYUS8213WgUOuayDaxu3JX1kq4cMiPL6XWC
gznYdRDrO/92E5OyOjmrAGzItDv/SIoBGv68f/kxYC989H+yd7aCqF8SfRlR0ESi
PnLLSYZfRsB4oLeSpkECQQDZdMLOZ3uiRwBvPV79mqfmME2OpB5VssAS9GO+giF3
c8jibpre2wV/xWZ4/ACeXmFRgejVp09JEvF2OARhgSyVAkEAxNGxzJH22E0ZT3kq
W7L7o8mkCQVjLK99dMaagUg+VpKk+4Y02hBStLP4xnIHt7NfpQ7r+cebk3ZeH5Ep
hO7PCQJBALcKhpPxHWuKcn4wXY4BKYUkcZQ452Phk7YgyvjoVr1S0+xth6VBHU7g
3ZHHJcoozagrPs7hB2cOL/v/yQg+EEUCQH5Ila5OkXWjsnO9qKIBq1giDvAC1ulb
CEIfFA+TjPv7R4RjThIEmyx6tUqO68jAfMPpWRuBKZ9qOWZDu8IhgBECQCZTubwP
zZ+9Kntj9BcoRjYYMeWK8voPzS4n1S8PK3249e7GdfX/Z7OcsvV9gYJ7CZ6W41fo
wa3MnlkEivo3mrA=
-----END PRIVATE KEY-----`;
const text = "some data";
const enc = crypt.encrypt(text);
const dec = crypt.decrypt(enc);
console.log('enc:', enc);
const temp = 'EutZlbeFV2RTG8mk6xUMi/ceN1hmj/xFre+7GkmFMBX5ZTl+rpQlJfZC9uoBBO8ywoi0YceF+lXgpDlvMxUTKnK7nLjt2L4AWEBCXT5XNKdK83N4kkMgZkZocoTD/I7mBBJQ7ZHRgtMRIoPoVBKz2HhGaK2tq3U1lDtkDACuZ3k= ';
// temp is cut and paste from previous console log
const dec2 = crypt.decrypt(temp);
console.log('dec2:', dec2); // prints null