Class OpensslCipher
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidclean()Forcibly clean the context.intdoFinal(ByteBuffer output) Finishes a multiple-part operation.protected voidfinalize()static OpensslCiphergetInstance(String transformation) static OpensslCiphergetInstance(String transformation, String engineId) Return anOpensslCipherobject that implements the specified transformation.static Stringstatic Stringvoidinit(int mode, byte[] key, byte[] iv) Initialize this cipher with a key and IV.static booleanisSupported(CipherSuite suite) intupdate(ByteBuffer input, ByteBuffer output) Continues a multiple-part encryption or decryption operation.
-
Field Details
-
ENCRYPT_MODE
public static final int ENCRYPT_MODE- See Also:
-
DECRYPT_MODE
public static final int DECRYPT_MODE- See Also:
-
-
Method Details
-
getLoadingFailureReason
-
getInstance
public static OpensslCipher getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException -
getInstance
public static OpensslCipher getInstance(String transformation, String engineId) throws NoSuchAlgorithmException, NoSuchPaddingException Return anOpensslCipherobject 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
OpensslCipherobject - Throws:
NoSuchAlgorithmException- iftransformationis null, empty, in an invalid format, or if Openssl doesn't implement the specified algorithm.NoSuchPaddingException- iftransformationcontains a padding scheme that is not available.
-
isSupported
-
init
public void init(int mode, byte[] key, byte[] iv) Initialize this cipher with a key and IV.- Parameters:
mode-ENCRYPT_MODEorDECRYPT_MODEkey- crypto keyiv- crypto iv
-
update
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 atinput.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, aShortBufferExceptionis thrown.- Parameters:
input- the input ByteBufferoutput- the output ByteBuffer- Returns:
- int number of bytes stored in
output - Throws:
ShortBufferException- if there is insufficient space in the output buffer
-
doFinal
public int doFinal(ByteBuffer output) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException 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.
Ifoutput.remaining()bytes are insufficient to hold the result, aShortBufferExceptionis 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
-
getLibraryName
-