.env
'exposed_headers' => ['Authorization'],
index.ts
AES_SECRET= 123
错误-对象可能是'undefined'。 秘密显示为未定义
答案 0 :(得分:2)
尝试这样:
dotenv.config();
const secret = <string>process.env.AES_SECRET;
.
.
const decrypt = (hash: string) => {
var reb64 = CryptoJS.enc.Hex.parse(hash);
var bytes = reb64.toString(CryptoJS.enc.Base64);
var decrypt;
if (secret !== undefined) {
decrypt = AES.decrypt(bytes, secret);
}
var plainText = decrypt.toString(CryptoJS.enc.Utf8);
return plainText
}
答案 1 :(得分:0)
已更新: 我最终这样做了
const presecret = process.env.AES_SECRET;
const secret = presecret!.toString();