Package org.apache.cassandra.security
Class EncryptionUtils
java.lang.Object
org.apache.cassandra.security.EncryptionUtils
Encryption and decryption functions specific to the commit log.
See comments in
EncryptedSegment for details on the binary format.
The normal, and expected, invocation pattern is to compress then encrypt the data on the encryption pass,
then decrypt and uncompress the data on the decrypt pass.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ByteBuffercompress(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) Compress the raw data, as well as manage sizing of theoutputBuffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer.static ByteBufferdecrypt(ReadableByteChannel channel, ByteBuffer outputBuffer, boolean allowBufferResize, Cipher cipher) Decrypt the input data, as well as manage sizing of theoutputBuffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer.static ByteBufferdecrypt(FileDataInput fileDataInput, ByteBuffer outputBuffer, boolean allowBufferResize, Cipher cipher) static ByteBufferencrypt(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, Cipher cipher) static ByteBufferencryptAndWrite(ByteBuffer inputBuffer, WritableByteChannel channel, boolean allowBufferResize, Cipher cipher) Encrypt the input data, and writes out to the same input buffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer.static intuncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, ICompressor compressor) static ByteBufferuncompress(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) Uncompress the input data, as well as manage sizing of theoutputBuffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer.
-
Field Details
-
COMPRESSED_BLOCK_HEADER_SIZE
public static final int COMPRESSED_BLOCK_HEADER_SIZE- See Also:
-
ENCRYPTED_BLOCK_HEADER_SIZE
public static final int ENCRYPTED_BLOCK_HEADER_SIZE- See Also:
-
-
Constructor Details
-
EncryptionUtils
public EncryptionUtils()
-
-
Method Details
-
compress
public static ByteBuffer compress(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) throws IOException Compress the raw data, as well as manage sizing of theoutputBuffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer. Write the two header lengths (plain text length, compressed length) to the beginning of the buffer as we want those values encapsulated in the encrypted block, as well.- Returns:
- the byte buffer that was actaully written to; it may be the
outputBufferif it had enough capacity, or it may be a new, larger instance. Callers should capture the return buffer (if calling multiple times). - Throws:
IOException
-
encryptAndWrite
public static ByteBuffer encryptAndWrite(ByteBuffer inputBuffer, WritableByteChannel channel, boolean allowBufferResize, Cipher cipher) throws IOException Encrypt the input data, and writes out to the same input buffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer. Writes the cipher text and headers out to the channel, as well. Note: channel is a parameter as we cannot write header info to the output buffer as we assume the input and output buffers can be the same buffer (and writing the headers to a shared buffer will corrupt any input data). Hence, we write out the headers directly to the channel, and then the cipher text (once encrypted).- Throws:
IOException
-
encrypt
public static ByteBuffer encrypt(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, Cipher cipher) throws IOException - Throws:
IOException
-
decrypt
public static ByteBuffer decrypt(ReadableByteChannel channel, ByteBuffer outputBuffer, boolean allowBufferResize, Cipher cipher) throws IOException Decrypt the input data, as well as manage sizing of theoutputBuffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer.- Returns:
- the byte buffer that was actaully written to; it may be the
outputBufferif it had enough capacity, or it may be a new, larger instance. Callers should capture the return buffer (if calling multiple times). - Throws:
IOException
-
decrypt
public static ByteBuffer decrypt(FileDataInput fileDataInput, ByteBuffer outputBuffer, boolean allowBufferResize, Cipher cipher) throws IOException - Throws:
IOException
-
uncompress
public static ByteBuffer uncompress(ByteBuffer inputBuffer, ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) throws IOException Uncompress the input data, as well as manage sizing of theoutputBuffer; if the buffer is not big enough, deallocate current, and allocate a large enough buffer.- Returns:
- the byte buffer that was actaully written to; it may be the
outputBufferif it had enough capacity, or it may be a new, larger instance. Callers should capture the return buffer (if calling multiple times). - Throws:
IOException
-
uncompress
public static int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, ICompressor compressor) throws IOException - Throws:
IOException
-