乐趣区

关于javascript:Nodejs-AES-加密解密

装置

npm i crypto-js -S

应用

const aesCrypto = require('crypto-js/aes');
const utf8Encode = require("crypto-js/enc-utf8")

const secretKey = "your-secret-key"

// 加密
const encrypt = text => {let encryptedText = aesCrypto.encrypt(utf8Encode.parse(text), secretKey).toString();

    return encryptedText
}

// 解密
const decrypt = text => {let decryptText = aesCrypto.decrypt(text, secretKey).toString(utf8Encode)

    console.log(decryptText)

    return decryptText.toString(utf8Encode);
}

decrypt(encrypt("hello aes!")) // hello aes!

exports.aes = {encrypt, decrypt}
退出移动版