import CryptoJS from 'crypto-js';
export const encrypt = (string) => {
let password = process.env.APP_KEY;
var key = CryptoJS.enc.Utf8.parse(password);
var option = { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 };
var encrypted = CryptoJS.DES.encrypt(string, key, option);
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
};
export const decrypt = (base64Message) => {
let password = process.env.APP_KEY;
var key = CryptoJS.enc.Utf8.parse(password);
var decrypted = CryptoJS.DES.decrypt(base64Message, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
});
return decrypted.toString(CryptoJS.enc.Utf8);
};
关联:PHP 的 DES 加密与解密示例