请用cryptto库编写一个字符串AESl加解密的函数
时间: 2023-03-13 14:00:20 浏览: 133
AES加解密代码
我可以为您提供一个使用crypto库编写的AES加解密函数的示例:const crypto = require('crypto');// 加密函数
function encrypt(key, data) {
const cipher = crypto.createCipher('aes192', key);
let crypted = cipher.update(data, 'utf8', 'hex');
crypted += cipher.final('hex');
return crypted;
}// 解密函数
function decrypt(key, data) {
const decipher = crypto.createDecipher('aes192', key);
let decrypted = decipher.update(data, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
阅读全文