public class AESGCM extends Object
See draft-ietf-jose-json-web-algorithms-26, section 5.1 and appendix 3.
Modifier and Type | Field and Description |
---|---|
static int |
AUTH_TAG_BIT_LENGTH
The standard authentication tag length (128 bits).
|
static int |
IV_BIT_LENGTH
The standard Initialization Vector (IV) length (96 bits).
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
decrypt(SecretKey secretKey,
byte[] iv,
byte[] cipherText,
byte[] authData,
byte[] authTag)
Decrypts the specified cipher text using AES/GCM/NoPadding.
|
static AuthenticatedCipherText |
encrypt(SecretKey secretKey,
byte[] iv,
byte[] plainText,
byte[] authData)
Encrypts the specified plain text using AES/GCM/NoPadding.
|
static byte[] |
generateIV(SecureRandom randomGen)
Generates a random 96 bit (12 byte) Initialization Vector(IV) for use in AES-GCM encryption.
|
public static final int IV_BIT_LENGTH
public static final int AUTH_TAG_BIT_LENGTH
public static byte[] generateIV(SecureRandom randomGen)
See draft-ietf-jose-json-web-algorithms-26, section 5.3.
randomGen
- The secure random generator to use. Must be correctly initialized and not null
.public static AuthenticatedCipherText encrypt(SecretKey secretKey, byte[] iv, byte[] plainText, byte[] authData)
secretKey
- The AES key. Must not be null
.plainText
- The plain text. Must not be null
.iv
- The initialization vector (IV). Must not be null
.authData
- The authenticated data. Must not be null
.RuntimeException
- If encryption failed.public static byte[] decrypt(SecretKey secretKey, byte[] iv, byte[] cipherText, byte[] authData, byte[] authTag)
secretKey
- The AES key. Must not be null
.iv
- The initialisation vector (IV). Must not be null
.cipherText
- The cipher text. Must not be null
.authData
- The authenticated data. Must not be null
.authTag
- The authentication tag. Must not be null
.RuntimeException
- If decryption failed.Copyright © 2016. All rights reserved.