Commit 88c74ce6 by 朱建香

1027

parent 399e5f0f
/**
* @class
* crypto
*/
import CryptoJS from "crypto-js";
import md5 from "md5";
class crypto{
static MD5(string){
console.log(string);
return md5(string);
}
static enkey(string){
let key = this.MD5(string).substr(8,16);
let iv = this.MD5(key).substr(8,16);
let keyIv = {
"key": key,
"iv": iv
}
return keyIv;
}
static encode(msg, keyIv){
let message = JSON.stringify(msg);
let key = CryptoJS.enc.Utf8.parse(keyIv.key);
let iv = CryptoJS.enc.Utf8.parse(keyIv.iv);
let code = CryptoJS.AES.encrypt(message, key, { iv: iv},{ mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.nopadding });
return code.toString();
}
static decode(code, keyIv){
let key = CryptoJS.enc.Utf8.parse(keyIv.key);
let iv = CryptoJS.enc.Utf8.parse(keyIv.iv);;
let decryptedData = CryptoJS.AES.decrypt(code, key, { iv: iv},{ mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.nopadding });
return JSON.parse(decryptedData.toString(CryptoJS.enc.Utf8));
}
}
export default crypto;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment