类 UAes

java.lang.Object
com.gdxsoft.easyweb.utils.UAes
所有已实现的接口:
IUSymmetricEncyrpt

public class UAes extends Object implements IUSymmetricEncyrpt
AES Encrypt / Decrypt Utils GCM/CCM/CBC/ECB/CFB/OFB/CTR 128, 192, 256
  • 字段详细资料

  • 构造器详细资料

    • UAes

      public UAes()
      Initialize AES (AES_128_CBC)
    • UAes

      public UAes(String key, String iv)
      Initialize AES (AES_128_CBC)
      参数:
      key - key
      iv - iv
    • UAes

      public UAes(String key, String iv, String cipherName)
      Initialize AES
      参数:
      key - the password
      iv - the iv
      cipherName - the cipher name (aes-128-gcm ...)
    • UAes

      public UAes(byte[] keyBuf, byte[] ivBuf)
      Initialize AES (AES_128_CBC)
      参数:
      keyBuf - the password bytes
      ivBuf - the iv bytes
    • UAes

      public UAes(byte[] keyBuf, byte[] ivBuf, String cipherName)
      Initialize AES
      参数:
      keyBuf - the password bytes
      ivBuf - the iv bytes
      cipherName - the cipher name (aes-128-gcm ...)
  • 方法详细资料

    • initDefaultKey

      public static void initDefaultKey(String key, String iv)
      Initialize the default key and iv, the algorithm is AES_128_GCM
      参数:
      key - the key
      iv - the iv
    • initDefaultKey

      public static void initDefaultKey(String algorithm, String key, String iv)
      Initialize the default algorithm and key and iv
      参数:
      algorithm - the AES algorithm
      key - the key
      iv - the iv
    • initDefaultKey

      public static void initDefaultKey(String algorithm, String key, String iv, int macSize)
      Initialize the default algorithm and key and iv and macSize
      参数:
      algorithm - the AES algorithm (GCM/CCM)
      key - the key
      iv - the iv
      macSize - the GCM/CCM macBitSize
    • initDefaultKey

      public static void initDefaultKey(String algorithm, String key, String iv, int macSize, String aad)
      Initialize the default algorithm and key and iv and macSize and aad
      参数:
      algorithm - the AES algorithm (GCM/CCM)
      key - the key
      iv - the iv
      macSize - the GCM/CCM macBitSize
      aad - the GCM/CCM Additional AuthenticationData
    • getInstance

      public static UAes getInstance() throws Exception
      Get a AES with default key and iv
      返回:
      AES
      抛出:
      Exception
    • defaultEncrypt

      public static String defaultEncrypt(String plainText) throws Exception
      Default encrypt
      参数:
      plainText - plain text
      返回:
      Encrypted base64
      抛出:
      Exception
    • defaultDecrypt

      public static String defaultDecrypt(String base64Ciphertext) throws Exception
      Default decrypt
      参数:
      base64Ciphertext - Encrypted base64
      返回:
      Plain text
      抛出:
      Exception
    • encryptBytes

      public byte[] encryptBytes(byte[] plainData) throws Exception
      Encrypt data
      指定者:
      encryptBytes 在接口中 IUSymmetricEncyrpt
      参数:
      plainData - data
      返回:
      encrypted data
      抛出:
      Exception
    • decryptBytes

      public byte[] decryptBytes(byte[] encryptedData) throws Exception
      Decrypt data
      指定者:
      decryptBytes 在接口中 IUSymmetricEncyrpt
      参数:
      encryptedData - the encrypted data
      返回:
      plain data
      抛出:
      Exception
    • getBlockCipherMode

      public String getBlockCipherMode()
      Block cipher mode of operation, the default is CBC
      返回:
      CBC/CFB/ECB ...
    • generateRandomBytes

      public static byte[] generateRandomBytes(int Length)
      Generate a random buff
      参数:
      Length - the buff length
      返回:
      the random buff
    • encrypt

      public String encrypt(String source, String charsetName) throws Exception
      Encrypt String with charsetName
      指定者:
      encrypt 在接口中 IUSymmetricEncyrpt
      参数:
      source - the source string
      charsetName - the charsetNamee UTF8/GBK ...
      返回:
      the base64 encoded ciphertext
      抛出:
      Exception
    • encrypt

      public String encrypt(String source) throws Exception
      Encrypt String
      指定者:
      encrypt 在接口中 IUSymmetricEncyrpt
      参数:
      source - the UTF8 string
      返回:
      the base64 encoded ciphertext
      抛出:
      Exception
    • encode

      @Deprecated public String encode(String source) throws Exception
      已过时。
      Encrypt String, same as encrypt
      抛出:
      Exception
    • getEncString

      @Deprecated public String getEncString(String strMing) throws Exception
      已过时。
      Encrypt String, same as encrypt
      抛出:
      Exception
    • decrypt

      public String decrypt(String base64Ciphertext, String charsetName) throws Exception
      Decrypt the base64 encoded ciphertext
      指定者:
      decrypt 在接口中 IUSymmetricEncyrpt
      参数:
      base64Ciphertext - the base64 encoded ciphertext
      charsetName - the return text's character set
      返回:
      the plain text
      抛出:
      Exception
    • decrypt

      public String decrypt(String base64Ciphertext) throws Exception
      Decrypt the base64 encoded ciphertext
      指定者:
      decrypt 在接口中 IUSymmetricEncyrpt
      参数:
      base64Ciphertext - the base64 encoded ciphertext
      返回:
      the plain text (UTF8)
      抛出:
      Exception
    • decrypt

      public String decrypt(byte[] encryptedData) throws Exception
      Decrypt the encrypted data
      参数:
      encryptedData - the encrypted data
      返回:
      the plain text (UTF8)
      抛出:
      Exception
    • getKeyLength

      public int getKeyLength()
      AES key bytes length (16:128, 24:192, 32:256)
      返回:
      the key's length
    • getDesString

      @Deprecated public String getDesString(byte[] byteMi) throws Exception
      已过时。
      Decrypt
      抛出:
      Exception
    • decode

      @Deprecated public String decode(String base64Mi) throws Exception
      已过时。
      Decrypt
      抛出:
      Exception
    • getEncBytes

      @Deprecated public byte[] getEncBytes(String strMing) throws Exception
      已过时。
      Encrypt
      抛出:
      Exception
    • getDesString

      @Deprecated public String getDesString(String strMi) throws Exception
      已过时。
      Decrypt
      抛出:
      Exception
    • getDesBytes

      @Deprecated public byte[] getDesBytes(byte[] bytesEncrypt) throws Exception
      已过时。
      DecryptBytes
      抛出:
      Exception
    • createKey

      public void createKey(byte[] keyBytes)
      Initialize the password and iv
      iv = Reverse keyBytes
      参数:
      keyBytes - the password
    • getPaddingMethod

      public String getPaddingMethod()
      PADDING AES/CBC/PKCS7Padding
      返回:
      PADDING
    • setPaddingMethod

      public void setPaddingMethod(String paddingMethod)
      PADDING AES/CBC/PKCS7Padding
      参数:
      paddingMethod - PADDING
    • getCipherName

      public String getCipherName()
      Get then cipher name
      返回:
      the cipherName
    • setCipherName

      public void setCipherName(String cipherName)
      Set the cipher name
      参数:
      cipherName - the cipher name
    • getMacSizeBits

      public int getMacSizeBits()
      Get the GCM/CCM mac bits size, default is 128
      返回:
      the GCM/CCM mac bits size
    • setMacSizeBits

      public void setMacSizeBits(int macSizeBits)
      Set the GCM/CCM mac bits size, default is 128
      参数:
      macSizeBits - 32 ~ 128 , divisible by 8
    • isUsingBc

      public boolean isUsingBc()
      whether to use the BouncyCastle provider, default is BouncyCastle
      返回:
      whether to use the BouncyCastle
    • setUsingBc

      public void setUsingBc(boolean usingBc)
      Set whether to use the BouncyCastle provider
      参数:
      usingBc - true=BC,false=java.security
    • getAdditionalAuthenticationData

      public String getAdditionalAuthenticationData()
      Continues a multi-part update of the Additional AuthenticationData (AAD). Calls to this method provide AAD to the cipher when operating inmodes such as AEAD (GCM/CCM).
      返回:
      the AAD
    • setAdditionalAuthenticationData

      public void setAdditionalAuthenticationData(String additionalAuthenticationData)
      Continues a multi-part update of the Additional AuthenticationData (AAD). Calls to this method provide AAD to the cipher when operating inmodes such as AEAD (GCM/CCM).
      参数:
      additionalAuthenticationData - AAD
    • isAutoIv

      public boolean isAutoIv()
    • setAutoIv

      public void setAutoIv(boolean autoIv)
    • getMapCiphers

      public Map<String,OpCipher> getMapCiphers()