赞
踩
<script src="js/crypto-js.min.js"></script>
- /**
- * 解密
- * @param data 要解密的字符串
- * @param keys 秘钥
- * @returns {string} 解密后的字符串
- */
- aesDecrypt(data, keys) {
- let key = CryptoJS.enc.Utf8.parse(keys);//要和加密的密钥一样
- let decrypt = CryptoJS.AES.decrypt(data, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
- return CryptoJS.enc.Utf8.stringify(decrypt).toString();
- },
- /**
- * 加密
- * @param data 要加密的字符串
- * @param keys 秘钥
- * @returns {string} 加密后的字符串
- */
- aesEncrypt(data, keys) {
- let key = CryptoJS.enc.Utf8.parse(keys);
- let srcs = CryptoJS.enc.Utf8.parse(data);
- const encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
- return encrypted.toString();
- },
- //加密
- const epwd= aesEncrypt("abcd.1234567890","E6EAB77A-4513-4EB3-A56D-E8C435CE);
- console.log(epwd)
- //解密
- const dpwd= aesDecrypt(epwd,"E6EAB77A-4513-4EB3-A56D-E8C435CE),
- console.log(dpwd)
import CryptoJS from 'crypto-js';
-
-
-
- var app = new Vue({
- el: '#app',
- data() {
- return {}
- },
- methods: {
- /**
- * 解密
- * @param data 要解密的字符串
- * @param keys 秘钥
- * @returns {string} 解密后的字符串
- */
- aesDecrypt(data, keys) {
- let key = CryptoJS.enc.Utf8.parse(keys);//要和加密的密钥一样
- let decrypt = CryptoJS.AES.decrypt(data, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
- return CryptoJS.enc.Utf8.stringify(decrypt).toString();
- },
- /**
- * 加密
- * @param data 要加密的字符串
- * @param keys 秘钥
- * @returns {string} 加密后的字符串
- */
- aesEncrypt(data, keys) {
- let key = CryptoJS.enc.Utf8.parse(keys);
- let srcs = CryptoJS.enc.Utf8.parse(data);
- const encrypted = CryptoJS.AES.encrypt(srcs, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
- return encrypted.toString();
- },
- }
- //加密
- const epwd= this.aesEncrypt("abcd.1234567890","E6EAB77A-4513-4EB3-A56D-E8C435CE);
- console.log(epwd)
- //解密
- const dpwd= this.aesDecrypt(epwd,"E6EAB77A-4513-4EB3-A56D-E8C435CE),
- console.log(dpwd)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。