Interface Encryptor

All Known Implementing Classes:
JceCtrCryptoCodec.JceCtrCipher, OpensslCtrCryptoCodec.OpensslCtrCipher

@Private @Evolving public interface Encryptor
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    encrypt(ByteBuffer inBuffer, ByteBuffer outBuffer)
    This presents a direct interface encrypting with direct ByteBuffers.
    void
    init(byte[] key, byte[] iv)
    Initialize the encryptor and the internal encryption context.
    boolean
    Indicate whether the encryption context is reset.
  • Method Details

    • init

      void init(byte[] key, byte[] iv) throws IOException
      Initialize the encryptor and the internal encryption context.
      Parameters:
      key - encryption key.
      iv - encryption initialization vector
      Throws:
      IOException - if initialization fails
    • isContextReset

      boolean isContextReset()
      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.

      Returns:
      boolean whether context is reset.
    • encrypt

      void encrypt(ByteBuffer inBuffer, ByteBuffer outBuffer) throws IOException
      This presents a direct interface encrypting with direct ByteBuffers.

      This function does not always encrypt the entire buffer and may potentially need to be called multiple times to process an entire buffer. The object may hold the encryption context internally.

      Some implementations may require sufficient space in the destination buffer to encrypt the entire input buffer.

      Upon return, inBuffer.position() will be advanced by the number of bytes read and outBuffer.position() by bytes written. Implementations should not modify inBuffer.limit() and outBuffer.limit().

      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