Class LegacyAESGCM


  • @ThreadSafe
    public class LegacyAESGCM
    extends java.lang.Object
    Legacy AES/GSM/NoPadding encryption and decryption methods. Uses the BouncyCastle.org API. This class is thread-safe.
    Version:
    2015-11-15
    Author:
    Vladimir Dzhuvinov, Axel Nennker
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int AUTH_TAG_BIT_LENGTH
      The standard authentication tag length (128 bits).
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.bouncycastle.crypto.engines.AESEngine createAESCipher​(javax.crypto.SecretKey secretKey, boolean forEncryption)
      Creates a new AES cipher.
      static byte[] decrypt​(javax.crypto.SecretKey secretKey, byte[] iv, byte[] cipherText, byte[] authData, byte[] authTag)
      Decrypts the specified cipher text using AES/GCM/NoPadding.
      static AuthenticatedCipherText encrypt​(javax.crypto.SecretKey secretKey, byte[] iv, byte[] plainText, byte[] authData)
      Encrypts the specified plain text using AES/GCM/NoPadding.
      • Methods inherited from class java.lang.Object

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

      • AUTH_TAG_BIT_LENGTH

        public static final int AUTH_TAG_BIT_LENGTH
        The standard authentication tag length (128 bits).
        See Also:
        Constant Field Values
    • Method Detail

      • createAESCipher

        public static org.bouncycastle.crypto.engines.AESEngine createAESCipher​(javax.crypto.SecretKey secretKey,
                                                                                boolean forEncryption)
        Creates a new AES cipher.
        Parameters:
        secretKey - The AES key. Must not be null.
        forEncryption - If true creates an AES encryption cipher, else creates an AES decryption cipher.
        Returns:
        The AES cipher.
      • encrypt

        public static AuthenticatedCipherText encrypt​(javax.crypto.SecretKey secretKey,
                                                      byte[] iv,
                                                      byte[] plainText,
                                                      byte[] authData)
                                               throws JOSEException
        Encrypts the specified plain text using AES/GCM/NoPadding.
        Parameters:
        secretKey - The AES key. Must not be null.
        plainText - The plain text. Must not be null.
        iv - The initialisation vector (IV). Must not be null.
        authData - The authenticated data. Must not be null.
        Returns:
        The authenticated cipher text.
        Throws:
        JOSEException - If encryption failed.
      • decrypt

        public static byte[] decrypt​(javax.crypto.SecretKey secretKey,
                                     byte[] iv,
                                     byte[] cipherText,
                                     byte[] authData,
                                     byte[] authTag)
                              throws JOSEException
        Decrypts the specified cipher text using AES/GCM/NoPadding.
        Parameters:
        secretKey - The AES key. Must not be null.
        iv - The initialisation vector (IV). Must not be null.
        cipherText - The cipher text. Must not be null.
        authData - The authenticated data. Must not be null.
        authTag - The authentication tag. Must not be null.
        Returns:
        The decrypted plain text.
        Throws:
        JOSEException - If decryption failed.