zoukankan      html  css  js  c++  java
  • 【原创】【aes加密】

    1.  npm i crypto-js
    ========================================================================================
    2.  libs下新建aes.js
    ========================================================================================
    const CryptoJS = require("crypto-js"); //引用AES源码js

    const key = CryptoJS.enc.Utf8.parse("1234123412ABCDEF"); //十六位十六进制数作为密钥
    const iv = CryptoJS.enc.Utf8.parse("ABCDEF1234123412"); //十六位十六进制数作为密钥偏移量

    //解密方法
    function Decrypt(word) {
      let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
      let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
      let decrypt = CryptoJS.AES.decrypt(srcs, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7,
      });
      let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
      return decryptedStr.toString();
    }

    //加密方法
    function Encrypt(word) {
      let srcs = CryptoJS.enc.Utf8.parse(word);
      let encrypted = CryptoJS.AES.encrypt(srcs, key, {
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7,
      });
      return encrypted.ciphertext.toString().toUpperCase();
    }

    export default {
      Decrypt,
      Encrypt,
    };
    ========================================================================================
    3.  加密
    import aes from '@/libs/aes'
    aes.Encrypt(“内容”)
    ========================================================================================
    4.  解密
    import aes from '@/libs/aes'
    aes.Decrypt(“内容”)
    ========================================================================================
  • 相关阅读:
    HTML基础-第一讲
    DIV中display和visibility属性差别
    1.html+css页面设计
    Log4j中为什么设计isDebugEnabled()方法
    CI中写原生SQL(封装查询)
    codeigniter 对数据库的常用操作
    CI中PHP写法规范(不断更新)
    CI中自定义SQL查询,LIKE模糊查询的处理
    CI中REST URL含有中文怎么处理(报错:The URI you submitted has disallowed characters)
    MyISAM InnoDB 区别
  • 原文地址:https://www.cnblogs.com/Forever-0209/p/14923381.html
Copyright © 2011-2022 走看看