Class AesGcmUtil
- java.lang.Object
-
- hu.icellmobilsoft.coffee.tool.utils.crypto.AesGcmUtil
-
public class AesGcmUtil extends Object
Util class for AES/GCM/NoPadding encode/decode- Since:
- 1.1.0
- Author:
- mark.petrenyi
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]DEFAULT_IVDefault Initialization Vector (IV) buffer
-
Constructor Summary
Constructors Constructor Description AesGcmUtil()Default constructor, constructs a new object.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decryptWithAes256GcmNoPadding(byte[] oneTimeKey, byte[] encryptedBytes)AES-256 decrypting (GCM, NoPadding) with one time key (Since the default IV is used, the key must NOT be reused!)static byte[]decryptWithAes256GcmNoPadding(byte[] key, byte[] encryptedBytes, byte[] iv)AES-256 decrypting (GCM, NoPadding)static byte[]encryptWithAes256GcmNoPadding(byte[] oneTimeKey, byte[] plainText)AES-256 encrypting (GCM, NoPadding) with one time key (Since the default IV is used, the key must NOT be reused!)static byte[]encryptWithAes256GcmNoPadding(byte[] key, byte[] plainText, byte[] iv)AES-256 encrypting (GCM, NoPadding)static byte[]generateIv()Generates a secure random 12 byte length ivstatic byte[]generateKey()Generates a secure random 256 bit length key
-
-
-
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.BaseExceptionAES-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 encryptionplainText- - 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.BaseExceptionAES-256 encrypting (GCM, NoPadding)- Parameters:
key- - key used for encryptionplainText- - byte array to encryptiv- - 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.BaseExceptionAES-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 decryptingencryptedBytes- - 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.BaseExceptionAES-256 decrypting (GCM, NoPadding)- Parameters:
key- - key used for decryptingencryptedBytes- - byte array to decryptiv- - initialization vector- Returns:
- decrypted data as byte array
- Throws:
hu.icellmobilsoft.coffee.dto.exception.BaseException- exception
-
-