ace加密和解密(encrypt、decrypt)

//import CryptoJS from 'crypto-js'
 
import VueInst from "./instvue.js"
const CBCIV = "dfswaesk20201118";

export default {
    //加密
    encrypt(data, enckey) {
        if (!enckey) { enckey = CBCIV;}        
        var tmpvue = VueInst();    
        // data = CryptoJS.MD5("copyright." + data + "pms@2016").toString();
        let key = tmpvue.$crypto.enc.Utf8.parse(enckey);
        let secretData = tmpvue.$crypto.enc.Utf8.parse(data);
        let encrypted = tmpvue.$crypto.AES.encrypt(
            secretData,
            key,
            {mode:tmpvue.$crypto.mode.ECB,padding: tmpvue.$crypto.pad.Pkcs7
            }
        );
        return encrypted.toString();
    },

    //解密
    decrypt(data, enckey) {
        if (!enckey) { enckey = CBCIV;}      
        var tmpvue = VueInst();  
        let key = tmpvue.$crypto.enc.Utf8.parse(enckey);
        let decrypt = tmpvue.$crypto.AES.decrypt(
            data,
            key,
            {
              mode:tmpvue.$crypto.mode.ECB,padding: tmpvue.$crypto.pad.Pkcs7
            });
        return tmpvue.$crypto.enc.Utf8.stringify(decrypt).toString();
    }
}
import Vue from "vue";
export default function getVueInst() {
   // return new Promise((resolve, reject) =>{
    var tmpvue = null;
        if (window.$vm) {
            tmpvue = window.$vm;
          //  //console.log("tmpvue-- window.$vm",tmpvue)
        }
        else {
            tmpvue = new Vue({})
          //  //console.log("tmpvue--new Vue()", tmpvue)
          //  //console.log("tmpvue--new tmpvue.$store", tmpvue.$store)
          //  //console.log("tmpvue--new tmpvue.$message", tmpvue.$message)
        }
         
        return tmpvue;      
 //   });
}

你可能感兴趣的:(前端,vue.js,javascript,前端)