var CryptoJS = require('crypto-js');
var config = require('../config/config');
var desUtil = {
encryptByDESModeEBC: function encryptByDESModeEBC(message) {
var keyHex = CryptoJS.enc.Utf8.parse(config.salt);
var encrypted = CryptoJS.DES.encrypt(message, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.ciphertext.toString(); //DES ECB模式加密
},
decryptByDESModeEBC: function decryptByDESModeEBC(ciphertext) {
var keyHex = CryptoJS.enc.Utf8.parse(config.salt);
var decrypted = CryptoJS.DES.decrypt({
ciphertext: CryptoJS.enc.Hex.parse(ciphertext)
}, keyHex, {
mode: CryptoJS.moddesUtile.ECB,
padding: CryptoJS.pad.Pkcs7
});
var result_value = decrypted.toString(CryptoJS.enc.Utf8);
return result_value; //DES ECB模式解密
}
}
module.exports = desUtil;