Class AesCtrJceCipher

  • All Implemented Interfaces:
    IndCpaCipher

    public final class AesCtrJceCipher
    extends java.lang.Object
    implements IndCpaCipher
    The primitive implements AES counter mode with random IVs, using JCE.

    Warning

    It is safe against chosen-plaintext attacks, but does not provide ciphertext integrity, thus is unsafe against chosen-ciphertext attacks.

    Since:
    1.0.0
    • Constructor Summary

      Constructors 
      Constructor Description
      AesCtrJceCipher​(byte[] key, int ivSize)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] decrypt​(byte[] ciphertext)
      Decrypts the ciphertext with counter mode decryption.
      byte[] encrypt​(byte[] plaintext)
      Encrypts the plaintext with counter mode encryption using randomly generated iv.
      • Methods inherited from class java.lang.Object

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

      • AesCtrJceCipher

        public AesCtrJceCipher​(byte[] key,
                               int ivSize)
                        throws java.security.GeneralSecurityException
        Throws:
        java.security.GeneralSecurityException
    • Method Detail

      • encrypt

        public byte[] encrypt​(byte[] plaintext)
                       throws java.security.GeneralSecurityException
        Encrypts the plaintext with counter mode encryption using randomly generated iv. The output format is iv || raw ciphertext.
        Specified by:
        encrypt in interface IndCpaCipher
        Parameters:
        plaintext - the plaintext to be encrypted.
        Returns:
        the encryption of plaintext.
        Throws:
        java.security.GeneralSecurityException
      • decrypt

        public byte[] decrypt​(byte[] ciphertext)
                       throws java.security.GeneralSecurityException
        Decrypts the ciphertext with counter mode decryption. The ciphertext format is iv || raw ciphertext.
        Specified by:
        decrypt in interface IndCpaCipher
        Parameters:
        ciphertext - the ciphertext to be decrypted.
        Returns:
        the decrypted plaintext.
        Throws:
        java.security.GeneralSecurityException