(Java) AES-128 数据加密

 

 

package com.vcgeek.hephaestus.utils;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;


public class AESUtil {

    //  AES-128 数据加密的 JAVA 实现
    public static byte[] Encrypt(byte[] sSrc, byte[] sKey){
        try{
            SecretKeySpec skeySpec = new SecretKeySpec(sKey, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
            cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
            byte[] encrypted = cipher.doFinal(sSrc);
            return encrypted;
        }catch(Exception ex){
            return null;
        }
    }

    //  AES-128 数据解密的 JAVA 实现
    public static byte[] Decrypt(byte[] sSrc, byte[] sKey){
        try{
            SecretKeySpec skeySpec = new SecretKeySpec(sKey, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
            cipher.init(Cipher.DECRYPT_MODE, skeySpec);
            byte[] dncrypted = cipher.doFinal(sSrc);
            return dncrypted;
        }catch(Exception ex){
            return null;
        }
    }

}

 

相关文章:

  • 2022-03-09
  • 2022-12-23
  • 2021-08-09
  • 2022-02-08
  • 2021-12-26
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-07
  • 2021-12-12
  • 2021-11-06
  • 2021-12-28
  • 2022-12-23
  • 2021-12-18
  • 2022-12-23
相关资源
相似解决方案