-
public interface FileContentCryptor
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleancanSkipAuthentication()intciphertextChunkSize()default longciphertextSize(long cleartextSize)Calculates the size of the ciphertext resulting from the given cleartext encrypted with the given cryptor.intcleartextChunkSize()default longcleartextSize(long ciphertextSize)Calculates the size of the cleartext resulting from the given ciphertext decrypted with the given cryptor.ByteBufferdecryptChunk(ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header, boolean authenticate)Decrypts a single chunk of ciphertext.voiddecryptChunk(ByteBuffer ciphertextChunk, ByteBuffer cleartextChunk, long chunkNumber, FileHeader header, boolean authenticate)Decrypts a single chunk of ciphertext.ByteBufferencryptChunk(ByteBuffer cleartextChunk, long chunkNumber, FileHeader header)Encrypts a single chunk of cleartext.voidencryptChunk(ByteBuffer cleartextChunk, ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header)Encrypts a single chunk of cleartext.
-
-
-
Method Detail
-
canSkipAuthentication
boolean canSkipAuthentication()
- Returns:
trueif it is technically possible to decrypt unauthentic ciphertext
-
cleartextChunkSize
int cleartextChunkSize()
- Returns:
- The number of cleartext bytes per chunk.
-
ciphertextChunkSize
int ciphertextChunkSize()
- Returns:
- The number of ciphertext bytes per chunk.
-
encryptChunk
ByteBuffer encryptChunk(ByteBuffer cleartextChunk, long chunkNumber, FileHeader header)
Encrypts a single chunk of cleartext.- Parameters:
cleartextChunk- Content to be encryptedchunkNumber- Number of the chunk to be encryptedheader- Header of the file, this chunk belongs to- Returns:
- Encrypted content.
-
encryptChunk
void encryptChunk(ByteBuffer cleartextChunk, ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header)
Encrypts a single chunk of cleartext.- Parameters:
cleartextChunk- Content to be encryptedciphertextChunk- Encrypted content buffer (with at leastciphertextChunkSize()remaining bytes)chunkNumber- Number of the chunk to be encryptedheader- Header of the file, this chunk belongs to
-
decryptChunk
ByteBuffer decryptChunk(ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header, boolean authenticate) throws AuthenticationFailedException
Decrypts a single chunk of ciphertext.- Parameters:
ciphertextChunk- Content to be decryptedchunkNumber- Number of the chunk to be decryptedheader- Header of the file, this chunk belongs toauthenticate- Skip authentication by setting this flag tofalse. Should always betrueby default.- Returns:
- Decrypted content. Position is set to
0and limit to the end of the chunk. - Throws:
AuthenticationFailedException- If authenticate istrueand the given chunk does not match its MAC.UnsupportedOperationException- If authenticate isfalsebut this cryptorcan not skip authentication.
-
decryptChunk
void decryptChunk(ByteBuffer ciphertextChunk, ByteBuffer cleartextChunk, long chunkNumber, FileHeader header, boolean authenticate) throws AuthenticationFailedException
Decrypts a single chunk of ciphertext.- Parameters:
ciphertextChunk- Content to be decryptedcleartextChunk- Buffer for decrypted chunk (with at leastcleartextChunkSize()remaining bytes)chunkNumber- Number of the chunk to be decryptedheader- Header of the file, this chunk belongs toauthenticate- Skip authentication by setting this flag tofalse. Should always betrueby default.- Throws:
AuthenticationFailedException- If authenticate istrueand the given chunk does not match its MAC.UnsupportedOperationException- If authenticate isfalsebut this cryptorcan not skip authentication.
-
cleartextSize
default long cleartextSize(long ciphertextSize)
Calculates the size of the cleartext resulting from the given ciphertext decrypted with the given cryptor.- Parameters:
ciphertextSize- Length of encrypted payload. Not including thelength of the header.- Returns:
- Cleartext length of a
ciphertextSize-sized ciphertext decrypted withcryptor.
-
ciphertextSize
default long ciphertextSize(long cleartextSize)
Calculates the size of the ciphertext resulting from the given cleartext encrypted with the given cryptor.- Parameters:
cleartextSize- Length of a unencrypted payload.- Returns:
- Ciphertext length of a
cleartextSize-sized cleartext encrypted withcryptor. Not including the length of the header.
-
-