zoukankan      html  css  js  c++  java
  • AES加密

    npm install crypto-js (项目中版本:^4.1.1)

    import { Injectable } from '@angular/core';
    import { AES, enc, mode, pad } from 'crypto-js';
    
    @Injectable()
    export class CryptoService {
      private key: string = '9c3f7e00e660448f60d988dcf45bc999';
      constructor() {
      }
      /**
       * AES加密
       */
      encryptByEnAES(data: string): string {
        let Key = enc.Utf8.parse(this.key);
        let tmpAES = AES.encrypt(enc.Utf8.parse(data), Key, {
          mode: mode.ECB,
          padding: pad.Pkcs7
        });
        return tmpAES.toString();
      }
    
      /**
       * AES解密
       */
      encryptByDeAES(data: string): string {
        let Key = enc.Utf8.parse(this.key);
        let tmpDeAES = AES.decrypt(data, Key, {
          mode: mode.ECB,
          padding: pad.Pkcs7
        });
        return tmpDeAES.toString(enc.Utf8);
      }
    }
    
  • 相关阅读:
    java--exceptions
    java-interface
    Java笔记
    memcpy
    const 关键字
    LeeCode整数 反转
    函数调用运算符笔记
    cvCreateImage
    c++继承笔记1
    虚拟机下的debian无法登陆
  • 原文地址:https://www.cnblogs.com/boreguo/p/15393115.html
Copyright © 2011-2022 走看看