Package io.grpc.alts.internal
Class AesGcmAeadCrypter
- java.lang.Object
-
- io.grpc.alts.internal.AesGcmAeadCrypter
-
- All Implemented Interfaces:
AeadCrypter
final class AesGcmAeadCrypter extends java.lang.Object implements AeadCrypter
AES128-GCM implementation ofAeadCrypterthat uses default JCE provider.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringAESprivate static java.lang.StringAES_GCMprivate javax.crypto.Ciphercipherprivate static java.security.ProviderCONSCRYPTprivate byte[]keyprivate static intKEY_LENGTHprivate static java.util.logging.Loggerlogger(package private) static intNONCE_LENGTHprivate static intTAG_LENGTH
-
Constructor Summary
Constructors Constructor Description AesGcmAeadCrypter(byte[] key)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddecrypt(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, byte[] nonce)Decrypt ciphertext into plaintext buffer using the given nonce.voiddecrypt(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer aad, byte[] nonce)Decrypt ciphertext into plaintext buffer using the given nonce.private voiddecryptAad(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer aad, byte[] nonce)voidencrypt(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, byte[] nonce)Encrypt plaintext into ciphertext buffer using the given nonce.voidencrypt(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, java.nio.ByteBuffer aad, byte[] nonce)Encrypt plaintext into ciphertext buffer using the given nonce with authenticated data.private intencryptAad(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, java.nio.ByteBuffer aad, byte[] nonce)(package private) static java.security.ProvidergetConscrypt()(package private) static intgetKeyLength()
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
KEY_LENGTH
private static final int KEY_LENGTH
- See Also:
- Constant Field Values
-
TAG_LENGTH
private static final int TAG_LENGTH
- See Also:
- Constant Field Values
-
NONCE_LENGTH
static final int NONCE_LENGTH
- See Also:
- Constant Field Values
-
AES
private static final java.lang.String AES
- See Also:
- Constant Field Values
-
AES_GCM
private static final java.lang.String AES_GCM
- See Also:
- Constant Field Values
-
CONSCRYPT
private static final java.security.Provider CONSCRYPT
-
key
private final byte[] key
-
cipher
private final javax.crypto.Cipher cipher
-
-
Method Detail
-
encryptAad
private int encryptAad(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, @Nullable java.nio.ByteBuffer aad, byte[] nonce) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
decryptAad
private void decryptAad(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, @Nullable java.nio.ByteBuffer aad, byte[] nonce) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
encrypt
public void encrypt(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, byte[] nonce) throws java.security.GeneralSecurityExceptionDescription copied from interface:AeadCrypterEncrypt plaintext into ciphertext buffer using the given nonce.- Specified by:
encryptin interfaceAeadCrypter- Parameters:
ciphertext- the encrypted plaintext and the tag will be written into this buffer.plaintext- the input that should be encrypted.nonce- the unique nonce used for the encryption.- Throws:
java.security.GeneralSecurityException- if ciphertext buffer is short or the nonce does not have the expected size.
-
encrypt
public void encrypt(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, java.nio.ByteBuffer aad, byte[] nonce) throws java.security.GeneralSecurityExceptionDescription copied from interface:AeadCrypterEncrypt plaintext into ciphertext buffer using the given nonce with authenticated data.- Specified by:
encryptin interfaceAeadCrypter- Parameters:
ciphertext- the encrypted plaintext and the tag will be written into this buffer.plaintext- the input that should be encrypted.aad- additional data that should be authenticated, but not encrypted.nonce- the unique nonce used for the encryption.- Throws:
java.security.GeneralSecurityException- if ciphertext buffer is short or the nonce does not have the expected size.
-
decrypt
public void decrypt(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, byte[] nonce) throws java.security.GeneralSecurityExceptionDescription copied from interface:AeadCrypterDecrypt ciphertext into plaintext buffer using the given nonce.- Specified by:
decryptin interfaceAeadCrypter- Parameters:
plaintext- the decrypted plaintext will be written into this buffer.ciphertext- the ciphertext and tag that should be decrypted.nonce- the nonce that was used for the encryption.- Throws:
java.security.GeneralSecurityException- if the tag is invalid or any of the inputs do not have the expected size.
-
decrypt
public void decrypt(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer aad, byte[] nonce) throws java.security.GeneralSecurityExceptionDescription copied from interface:AeadCrypterDecrypt ciphertext into plaintext buffer using the given nonce.- Specified by:
decryptin interfaceAeadCrypter- Parameters:
plaintext- the decrypted plaintext will be written into this buffer.ciphertext- the ciphertext and tag that should be decrypted.aad- additional data that is checked for authenticity.nonce- the nonce that was used for the encryption.- Throws:
java.security.GeneralSecurityException- if the tag is invalid or any of the inputs do not have the expected size.
-
getKeyLength
static int getKeyLength()
-
getConscrypt
static java.security.Provider getConscrypt()
-
-