NodeJS 节点已解密,但解密时某些字符损坏

jk9hmnmh  于 2022-12-12  发布在  Node.js
关注(0)|答案(1)|浏览(117)

我创建了一个函数来解密,但是在解密的时候一些字符被破坏了。这个问题可能是什么引起的?
{“text”:“aynīsī "}
1999年12月15日,纽约
{“text”:“aynìs "}

const encryptionType = 'aes-256-cbc';
const encryptionEncoding = 'base64';
const encryptionEncodingHex = 'hex';
const bufferEncryption = 'utf-8';

const decryptJwt = (cipherText) => {
  const buff = Buffer.from(cipherText, encryptionEncoding);
  const KEY = Buffer.from(SECRET, bufferEncryption);
  const IV = Buffer.alloc(16);

  const decipher = crypto.createDecipheriv(encryptionType, KEY, IV);
  const deciphered = decipher.update(buff).toString(bufferEncryption) + decipher.final().toString(bufferEncryption);

  return deciphered;
};
ruoxqz4g

ruoxqz4g1#

我修正:

let decrypted = decipher.update(buff, 'hex', 'utf8');

// Getting decrypted data
decrypted += decipher.final('utf8');

相关问题