public final class AesGcmSiv extends Object implements Aead
This encryption mode is intended for authenticated encryption with associated data. A major security problem with AES-GCM is that reusing the same nonce twice leaks the authentication key. AES-GCM-SIV on the other hand has been designed to avoid this vulnerability.
This encryption requires a JCE provider that supports the AES/GCM-SIV/NoPadding
transformation such as Conscrypt. using JCE.
| Modifier and Type | Class and Description |
|---|---|
static interface |
AesGcmSiv.ThrowingSupplier<T>
A supplier that can throw a
GeneralSecurityException. |
| Modifier and Type | Method and Description |
|---|---|
static Aead |
create(AesGcmSivKey key,
AesGcmSiv.ThrowingSupplier<Cipher> cipherSupplier)
Creates an Aead for AES GCM SIV.
|
byte[] |
decrypt(byte[] ciphertext,
byte[] associatedData)
On Android KitKat (API level 19) this method does not support non null or non empty
associatedData. |
byte[] |
encrypt(byte[] plaintext,
byte[] associatedData)
On Android KitKat (API level 19) this method does not support non null or non empty
associatedData. |
static boolean |
isAesGcmSivCipher(Cipher cipher)
Returns true if the cipher is an AES-GCM-SIV cipher.
|
public static boolean isAesGcmSivCipher(Cipher cipher)
On Android API version 29 and older, Cipher.getInstance("AES/GCM-SIV/NoPadding")
returns an AES-GCM cipher instead of an AES GCM SIV cipher. This function tests if we have a
correct cipher.
public static Aead create(AesGcmSivKey key, AesGcmSiv.ThrowingSupplier<Cipher> cipherSupplier) throws GeneralSecurityException
This function assumes that cipherSupplier provides correct implementations of AES GCM SIV.
CipherSupplier may use isAesGcmSivCipher to ensure this.
GeneralSecurityExceptionpublic byte[] encrypt(byte[] plaintext,
byte[] associatedData)
throws GeneralSecurityException
associatedData. It might not work at all in older versions.encrypt in interface Aeadplaintext - the plaintext to be encrypted. It must be non-null, but can also
be an empty (zero-length) byte arrayassociatedData - associated data to be authenticated, but not encrypted. Associated data
is optional, so this parameter can be null. In this case the null value
is equivalent to an empty (zero-length) byte array.
For successful decryption the same associatedData must be provided
along with the ciphertext.GeneralSecurityExceptionpublic byte[] decrypt(byte[] ciphertext,
byte[] associatedData)
throws GeneralSecurityException
associatedData. It might not work at all in older versions.decrypt in interface Aeadciphertext - the plaintext to be decrypted. It must be non-null.associatedData - associated data to be authenticated. For successful decryption it must be
the same as associatedData used during encryption. Can be null, which is equivalent to an
empty (zero-length) byte array.GeneralSecurityException - if decryption fails. Decryption must fail if ciphertext is not correctly authenticated for the given associatedData.