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 ofAeadCrypter
that uses default JCE provider.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
AES
private static java.lang.String
AES_GCM
private javax.crypto.Cipher
cipher
private static java.security.Provider
CONSCRYPT
private byte[]
key
private static int
KEY_LENGTH
private static java.util.logging.Logger
logger
(package private) static int
NONCE_LENGTH
private static int
TAG_LENGTH
-
Constructor Summary
Constructors Constructor Description AesGcmAeadCrypter(byte[] key)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
decrypt(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, byte[] nonce)
Decrypt ciphertext into plaintext buffer using the given nonce.void
decrypt(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer aad, byte[] nonce)
Decrypt ciphertext into plaintext buffer using the given nonce.private void
decryptAad(java.nio.ByteBuffer plaintext, java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer aad, byte[] nonce)
void
encrypt(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, byte[] nonce)
Encrypt plaintext into ciphertext buffer using the given nonce.void
encrypt(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 int
encryptAad(java.nio.ByteBuffer ciphertext, java.nio.ByteBuffer plaintext, java.nio.ByteBuffer aad, byte[] nonce)
(package private) static java.security.Provider
getConscrypt()
(package private) static int
getKeyLength()
-
-
-
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.GeneralSecurityException
Description copied from interface:AeadCrypter
Encrypt plaintext into ciphertext buffer using the given nonce.- Specified by:
encrypt
in 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.GeneralSecurityException
Description copied from interface:AeadCrypter
Encrypt plaintext into ciphertext buffer using the given nonce with authenticated data.- Specified by:
encrypt
in 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.GeneralSecurityException
Description copied from interface:AeadCrypter
Decrypt ciphertext into plaintext buffer using the given nonce.- Specified by:
decrypt
in 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.GeneralSecurityException
Description copied from interface:AeadCrypter
Decrypt ciphertext into plaintext buffer using the given nonce.- Specified by:
decrypt
in 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()
-
-