微信小程序实现aes-128-cbc加密与解密

encrypt.js

const c = require("crypto-js");
var x = {};

x.encrypt = function(key, iv, data)
{
    key = c.enc.Utf8.parse(key);
    iv = c.enc.Utf8.parse(iv);
    data = c.enc.Utf8.parse(data);
    var option = {
        iv: iv,
        mode: c.mode.CBC,
        padding: c.pad.Pkcs7
    };
    return c.AES.encrypt(data, key, option).toString();
};

x.decrypt = function(key, iv, data)
{
    key = c.enc.Utf8.parse(key);
    iv = c.enc.Utf8.parse(iv);
    var option = {
        iv: iv,
        mode: c.mode.CBC,
        padding: c.pad.Pkcs7
    };
    var decrypt = c.AES.decrypt(data, key, option);
    return c.enc.Utf8.stringify(decrypt).toString();
};

module.exports = x;

你可能感兴趣的:(微信小程序,aes)