Class AesGcmUtil


  • public class AesGcmUtil
    extends Object
    Util class for AES/GCM/NoPadding encode/decode
    Since:
    1.1.0
    Author:
    mark.petrenyi
    • Field Detail

      • DEFAULT_IV

        public static final byte[] DEFAULT_IV
        Default Initialization Vector (IV) buffer
    • Constructor Detail

      • AesGcmUtil

        public AesGcmUtil()
        Default constructor, constructs a new object.
    • Method Detail

      • generateKey

        public static byte[] generateKey()
        Generates a secure random 256 bit length key
        Returns:
        random secure key as byte array
      • generateIv

        public static byte[] generateIv()
        Generates a secure random 12 byte length iv
        Returns:
        random secure key as byte array
      • encryptWithAes256GcmNoPadding

        public static byte[] encryptWithAes256GcmNoPadding​(byte[] oneTimeKey,
                                                           byte[] plainText)
                                                    throws hu.icellmobilsoft.coffee.dto.exception.BaseException
        AES-256 encrypting (GCM, NoPadding) with one time key (Since the default IV is used, the key must NOT be reused!)
        Parameters:
        oneTimeKey - - one time key used for encryption
        plainText - - byte array to encrypt
        Returns:
        the encrypted data as byte array
        Throws:
        hu.icellmobilsoft.coffee.dto.exception.BaseException - exception
      • encryptWithAes256GcmNoPadding

        public static byte[] encryptWithAes256GcmNoPadding​(byte[] key,
                                                           byte[] plainText,
                                                           byte[] iv)
                                                    throws hu.icellmobilsoft.coffee.dto.exception.BaseException
        AES-256 encrypting (GCM, NoPadding)
        Parameters:
        key - - key used for encryption
        plainText - - byte array to encrypt
        iv - - initialization vector (NEVER use the same key-iv pair more than once)
        Returns:
        the encrypted data as byte array
        Throws:
        hu.icellmobilsoft.coffee.dto.exception.BaseException - exception
      • decryptWithAes256GcmNoPadding

        public static byte[] decryptWithAes256GcmNoPadding​(byte[] oneTimeKey,
                                                           byte[] encryptedBytes)
                                                    throws hu.icellmobilsoft.coffee.dto.exception.BaseException
        AES-256 decrypting (GCM, NoPadding) with one time key (Since the default IV is used, the key must NOT be reused!)
        Parameters:
        oneTimeKey - - one time key used for decrypting
        encryptedBytes - - byte array to decrypt
        Returns:
        decrypted data as byte array
        Throws:
        hu.icellmobilsoft.coffee.dto.exception.BaseException - exception
      • decryptWithAes256GcmNoPadding

        public static byte[] decryptWithAes256GcmNoPadding​(byte[] key,
                                                           byte[] encryptedBytes,
                                                           byte[] iv)
                                                    throws hu.icellmobilsoft.coffee.dto.exception.BaseException
        AES-256 decrypting (GCM, NoPadding)
        Parameters:
        key - - key used for decrypting
        encryptedBytes - - byte array to decrypt
        iv - - initialization vector
        Returns:
        decrypted data as byte array
        Throws:
        hu.icellmobilsoft.coffee.dto.exception.BaseException - exception