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

35次阅读

共计 486 个字符,预计需要花费 2 分钟才能阅读完成。

装置

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}

正文完
 0