Class OpensslCtrCryptoCodec.OpensslCtrCipher

java.lang.Object
org.apache.hadoop.crypto.OpensslCtrCryptoCodec.OpensslCtrCipher
All Implemented Interfaces:
Decryptor, Encryptor
Enclosing class:
OpensslCtrCryptoCodec

protected static class OpensslCtrCryptoCodec.OpensslCtrCipher extends Object implements Encryptor, Decryptor
  • Constructor Details

  • Method Details

    • init

      public void init(byte[] key, byte[] iv) throws IOException
      Description copied from interface: Encryptor
      Initialize the encryptor and the internal encryption context.
      Specified by:
      init in interface Decryptor
      Specified by:
      init in interface Encryptor
      Parameters:
      key - encryption key.
      iv - encryption initialization vector
      Throws:
      IOException - if initialization fails
    • encrypt

      public void encrypt(ByteBuffer inBuffer, ByteBuffer outBuffer) throws IOException
      AES-CTR will consume all of the input data. It requires enough space in the destination buffer to encrypt entire input buffer.
      Specified by:
      encrypt in interface Encryptor
      Parameters:
      inBuffer - a direct ByteBuffer to read from. inBuffer may not be null and inBuffer.remaining() must be > 0
      outBuffer - a direct ByteBuffer to write to. outBuffer may not be null and outBuffer.remaining() must be > 0
      Throws:
      IOException - if encryption fails
    • decrypt

      public void decrypt(ByteBuffer inBuffer, ByteBuffer outBuffer) throws IOException
      AES-CTR will consume all of the input data. It requires enough space in the destination buffer to decrypt entire input buffer.
      Specified by:
      decrypt in interface Decryptor
      Parameters:
      inBuffer - a direct ByteBuffer to read from. inBuffer may not be null and inBuffer.remaining() must be > 0
      outBuffer - a direct ByteBuffer to write to. outBuffer may not be null and outBuffer.remaining() must be > 0
      Throws:
      IOException - if decryption fails
    • isContextReset

      public boolean isContextReset()
      Description copied from interface: Encryptor
      Indicate whether the encryption context is reset.

      Certain modes, like CTR, require a different IV depending on the position in the stream. Generally, the encryptor maintains any necessary context for calculating the IV and counter so that no reinit is necessary during the encryption. Reinit before each operation is inefficient.

      Specified by:
      isContextReset in interface Decryptor
      Specified by:
      isContextReset in interface Encryptor
      Returns:
      boolean whether context is reset.