1.使用crypto-js,aes加密,一般可以对手机号,身份信息进行加密
import AES from 'crypto-js/aes';
import Utf8 from 'crypto-js/enc-utf8';
import padZeroPadding from 'crypto-js/pad-zeropadding';
let key = Utf8.parse('fad56/jRax5/71qM');
let iv = Utf8.parse('fad56/jRax5/71qM');
let options = { iv: iv, padding: padZeroPadding };
/**
* AES加密
* @param {any} word 加密数据
*/
export const cryptoEncrypt = (word) => {
let encrypted = AES.encrypt(Utf8.parse(word), key, options);
return encrypted.toString();
};
/**
* AES解密
* @param {any} word 解密数据
*/
export const cryptoDecrypt = (word) => {
let decrypt = AES.decrypt(word, key, options);
let decryptedStr = decrypt.toString(Utf8);
return decryptedStr;
};
key加密key值,iv加密偏移量,padding填充值,
提供一个测试的网站,可以进行相关加密的测试,http://www.hiencode.com/caes.html.