Class OpensslCipher

java.lang.Object
org.apache.hadoop.crypto.OpensslCipher

@Private public final class OpensslCipher extends Object
OpenSSL cipher using JNI. Currently only AES-CTR is supported. It's flexible to add other crypto algorithms/modes.
  • Field Details

  • Method Details

    • getLoadingFailureReason

      public static String getLoadingFailureReason()
    • getInstance

      public static OpensslCipher getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException
      Throws:
      NoSuchAlgorithmException
      NoSuchPaddingException
    • getInstance

      public static OpensslCipher getInstance(String transformation, String engineId) throws NoSuchAlgorithmException, NoSuchPaddingException
      Return an OpensslCipher object that implements the specified transformation.
      Parameters:
      transformation - the name of the transformation, e.g., AES/CTR/NoPadding.
      engineId - the openssl engine to use.if not set, defalut engine will be used.
      Returns:
      OpensslCipher an OpensslCipher object
      Throws:
      NoSuchAlgorithmException - if transformation is null, empty, in an invalid format, or if Openssl doesn't implement the specified algorithm.
      NoSuchPaddingException - if transformation contains a padding scheme that is not available.
    • isSupported

      public static boolean isSupported(CipherSuite suite)
    • init

      public void init(int mode, byte[] key, byte[] iv)
      Initialize this cipher with a key and IV.
      Parameters:
      mode - ENCRYPT_MODE or DECRYPT_MODE
      key - crypto key
      iv - crypto iv
    • update

      public int update(ByteBuffer input, ByteBuffer output) throws ShortBufferException
      Continues a multiple-part encryption or decryption operation. The data is encrypted or decrypted, depending on how this cipher was initialized.

      All input.remaining() bytes starting at input.position() are processed. The result is stored in the output buffer.

      Upon return, the input buffer's position will be equal to its limit; its limit will not have changed. The output buffer's position will have advanced by n, when n is the value returned by this method; the output buffer's limit will not have changed.

      If output.remaining() bytes are insufficient to hold the result, a ShortBufferException is thrown.

      Parameters:
      input - the input ByteBuffer
      output - the output ByteBuffer
      Returns:
      int number of bytes stored in output
      Throws:
      ShortBufferException - if there is insufficient space in the output buffer
    • doFinal

      Finishes a multiple-part operation. The data is encrypted or decrypted, depending on how this cipher was initialized.

      The result is stored in the output buffer. Upon return, the output buffer's position will have advanced by n, where n is the value returned by this method; the output buffer's limit will not have changed.

      If output.remaining() bytes are insufficient to hold the result, a ShortBufferException is thrown.

      Upon finishing, this method resets this cipher object to the state it was in when previously initialized. That is, the object is available to encrypt or decrypt more data.

      If any exception is thrown, this cipher object need to be reset before it can be used again.
      Parameters:
      output - the output ByteBuffer
      Returns:
      int number of bytes stored in output
      Throws:
      ShortBufferException - if there is insufficient space in the output buffer.
      IllegalBlockSizeException - This exception is thrown when the length of data provided to a block cipher is incorrect.
      BadPaddingException - This exception is thrown when a particular padding mechanism is expected for the input data but the data is not padded properly.
    • clean

      public void clean()
      Forcibly clean the context.
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • getLibraryName

      public static String getLibraryName()