public class AESCBC extends Object
Also supports the deprecated AES/CBC/HMAC encryption using a custom concat KDF (JOSE draft suite 08).
See draft-ietf-jose-json-web-algorithms-26, section 5.2.
Modifier and Type | Field and Description |
---|---|
static int |
IV_BIT_LENGTH
The standard Initialization Vector (IV) length (128 bits).
|
Modifier and Type | Method and Description |
---|---|
static byte[] |
computeAADLength(byte[] aad)
Computes the bit length of the specified Additional Authenticated Data (AAD).
|
static byte[] |
decrypt(SecretKey secretKey,
byte[] iv,
byte[] cipherText)
Decrypts the specified cipher text using AES/CBC/PKCS5Padding.
|
static byte[] |
decryptAuthenticated(SecretKey secretKey,
byte[] iv,
byte[] cipherText,
byte[] aad,
byte[] authTag)
Decrypts the specified cipher text using AES/CBC/PKCS5Padding/ HMAC-SHA2.
|
static byte[] |
encrypt(SecretKey secretKey,
byte[] iv,
byte[] plainText)
Encrypts the specified plain text using AES/CBC/PKCS5Padding.
|
static AuthenticatedCipherText |
encryptAuthenticated(SecretKey secretKey,
byte[] iv,
byte[] plainText,
byte[] aad)
Encrypts the specified plain text using AES/CBC/PKCS5Padding/ HMAC-SHA2.
|
static byte[] |
generateIV(SecureRandom randomGen)
Generates a random 128 bit (16 byte) Initialization Vector(IV) for use in AES-CBC encryption.
|
public static final int IV_BIT_LENGTH
public static byte[] generateIV(SecureRandom randomGen)
randomGen
- The secure random generator to use. Must be correctly initialized and not null
.public static byte[] encrypt(SecretKey secretKey, byte[] iv, byte[] plainText)
secretKey
- The AES key. Must not be null
.iv
- The initialization vector (IV). Must not be null
.plainText
- The plain text. Must not be null
.RuntimeException
- If encryption failed.public static byte[] computeAADLength(byte[] aad)
aad
- The Additional Authenticated Data (AAD). Must not be null
.public static AuthenticatedCipherText encryptAuthenticated(SecretKey secretKey, byte[] iv, byte[] plainText, byte[] aad)
See draft-ietf-jose-json-web-algorithms-26, section 5.2.
See draft-mcgrew-aead-aes-cbc-hmac-sha2-01
secretKey
- The secret key. Must be 256 or 512 bits long. Must not be null
.iv
- The initialisation vector (IV). Must not be null
.plainText
- The plain text. Must not be null
.aad
- The additional authenticated data. Must not be null
.RuntimeException
- If encryption failed.public static byte[] decrypt(SecretKey secretKey, byte[] iv, byte[] cipherText)
secretKey
- The AES key. Must not be null
.iv
- The initialization vector (IV). Must not be null
.cipherText
- The cipher text. Must not be null
.RuntimeException
- If decryption failed.public static byte[] decryptAuthenticated(SecretKey secretKey, byte[] iv, byte[] cipherText, byte[] aad, byte[] authTag)
See draft-ietf-jose-json-web-algorithms-26, section 5.2.
secretKey
- The secret key. Must be 256 or 512 bits long. Must not be null
.iv
- The initialization vector (IV). Must not be null
.cipherText
- The cipher text. Must not be null
.aad
- The additional authenticated data. Must not be null
.authTag
- The authentication tag. Must not be null
.RuntimeException
- If decryption failed.Copyright © 2014. All rights reserved.