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;

xxfaxy
1.6k 声望18 粉丝