Package org.apache.cassandra.security
Class EncryptionUtils
- java.lang.Object
-
- org.apache.cassandra.security.EncryptionUtils
-
public class EncryptionUtils extends java.lang.ObjectEncryption and decryption functions specific to the commit log. See comments inEncryptedSegmentfor 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 Modifier and Type Class Description static classEncryptionUtils.ChannelProxyReadChannel
-
Field Summary
Fields Modifier and Type Field Description static intCOMPRESSED_BLOCK_HEADER_SIZEstatic intENCRYPTED_BLOCK_HEADER_SIZE
-
Constructor Summary
Constructors Constructor Description EncryptionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.nio.ByteBuffercompress(java.nio.ByteBuffer inputBuffer, java.nio.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 java.nio.ByteBufferdecrypt(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, javax.crypto.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 java.nio.ByteBufferdecrypt(FileDataInput fileDataInput, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, javax.crypto.Cipher cipher)static java.nio.ByteBufferencrypt(java.nio.ByteBuffer inputBuffer, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, javax.crypto.Cipher cipher)static java.nio.ByteBufferencryptAndWrite(java.nio.ByteBuffer inputBuffer, java.nio.channels.WritableByteChannel channel, boolean allowBufferResize, javax.crypto.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 java.nio.ByteBufferuncompress(java.nio.ByteBuffer inputBuffer, java.nio.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 Detail
-
COMPRESSED_BLOCK_HEADER_SIZE
public static final int COMPRESSED_BLOCK_HEADER_SIZE
- See Also:
- Constant Field Values
-
ENCRYPTED_BLOCK_HEADER_SIZE
public static final int ENCRYPTED_BLOCK_HEADER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
compress
public static java.nio.ByteBuffer compress(java.nio.ByteBuffer inputBuffer, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) throws java.io.IOExceptionCompress 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:
java.io.IOException
-
encryptAndWrite
public static java.nio.ByteBuffer encryptAndWrite(java.nio.ByteBuffer inputBuffer, java.nio.channels.WritableByteChannel channel, boolean allowBufferResize, javax.crypto.Cipher cipher) throws java.io.IOExceptionEncrypt 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:
java.io.IOException
-
encrypt
public static java.nio.ByteBuffer encrypt(java.nio.ByteBuffer inputBuffer, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, javax.crypto.Cipher cipher) throws java.io.IOException- Throws:
java.io.IOException
-
decrypt
public static java.nio.ByteBuffer decrypt(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, javax.crypto.Cipher cipher) throws java.io.IOExceptionDecrypt 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:
java.io.IOException
-
decrypt
public static java.nio.ByteBuffer decrypt(FileDataInput fileDataInput, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, javax.crypto.Cipher cipher) throws java.io.IOException
- Throws:
java.io.IOException
-
uncompress
public static java.nio.ByteBuffer uncompress(java.nio.ByteBuffer inputBuffer, java.nio.ByteBuffer outputBuffer, boolean allowBufferResize, ICompressor compressor) throws java.io.IOExceptionUncompress 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:
java.io.IOException
-
uncompress
public static int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, ICompressor compressor) throws java.io.IOException- Throws:
java.io.IOException
-
-