前端加密解密
1.安装:npm install crypto-js
2.在utils下创建一个cryptoAES.js
import CryptoJS from 'crypto-js';
//与后端约定的key
const DESKey = 'httt360fusion';
//加密
export function encryptedDES(data) {
const keyHex = CryptoJS.enc.Utf8.parse(DESKey);
//模式为ECB padding为Pkcs7
const encrypted = CryptoJS.DES.encrypt(JSON.stringify(data), keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
//加密出来是一个16进制的字符串
return encrypted.ciphertext.toString();
}
//解密
export function decryptedDES(data) {
const keyHex = CryptoJS.enc.Utf8.parse(DESKey);
const decrypted = CryptoJS.DES.decrypt({
ciphertext: CryptoJS.enc.Hex.parse(data)
}, keyHex, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
//以utf-8的形式输出解密过后内容
return decrypted.toString(CryptoJS.enc.Utf8);
}
3.方法调用
import {encryptedDES} from "../../../utils/cryptoAES";
encryptedDES(this.fromData)
Java加密解密
参考:https://blog.csdn.net/u013000304/article/details/85772542