Class AesGcmJce

  • All Implemented Interfaces:
    Aead

    @Immutable
    public final class AesGcmJce
    extends java.lang.Object
    implements Aead
    This primitive implements AesGcm using JCE.
    Since:
    1.0.0
    • Constructor Summary

      Constructors 
      Constructor Description
      AesGcmJce​(byte[] key)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static Aead create​(AesGcmKey key)  
      byte[] decrypt​(byte[] ciphertext, byte[] associatedData)
      Decrypts ciphertext with associatedData as associated authenticated data.
      byte[] encrypt​(byte[] plaintext, byte[] associatedData)
      On Android KitKat (API level 19) this method does not support non null or non empty associatedData.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AesGcmJce

        public AesGcmJce​(byte[] key)
                  throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
    • Method Detail

      • create

        public static Aead create​(AesGcmKey key)
                           throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
      • encrypt

        public byte[] encrypt​(byte[] plaintext,
                              byte[] associatedData)
                       throws java.security.GeneralSecurityException
        On Android KitKat (API level 19) this method does not support non null or non empty associatedData. It might not work at all in older versions.
        Specified by:
        encrypt in interface Aead
        Parameters:
        plaintext - the plaintext to be encrypted. It must be non-null, but can also be an empty (zero-length) byte array
        associatedData - 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.
        Returns:
        resulting ciphertext
        Throws:
        java.security.GeneralSecurityException
      • decrypt

        public byte[] decrypt​(byte[] ciphertext,
                              byte[] associatedData)
                       throws java.security.GeneralSecurityException
        Description copied from interface: Aead
        Decrypts ciphertext with associatedData as associated authenticated data. The decryption verifies the authenticity and integrity of the associated data, but there are no guarantees wrt. secrecy of that data.
        Specified by:
        decrypt in interface Aead
        Parameters:
        ciphertext - 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.
        Returns:
        resulting plaintext
        Throws:
        java.security.GeneralSecurityException - if decryption fails. Decryption must fail if ciphertext is not correctly authenticated for the given associatedData.