Package org.cryptomator.cryptolib.api
Interface FileContentCryptor
-
public interface FileContentCryptor
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
canSkipAuthentication()
int
ciphertextChunkSize()
default long
ciphertextSize(long cleartextSize)
Calculates the size of the ciphertext resulting from the given cleartext encrypted with the given cryptor.int
cleartextChunkSize()
default long
cleartextSize(long ciphertextSize)
Calculates the size of the cleartext resulting from the given ciphertext decrypted with the given cryptor.ByteBuffer
decryptChunk(ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header, boolean authenticate)
Decrypts a single chunk of ciphertext.void
decryptChunk(ByteBuffer ciphertextChunk, ByteBuffer cleartextChunk, long chunkNumber, FileHeader header, boolean authenticate)
Decrypts a single chunk of ciphertext.ByteBuffer
encryptChunk(ByteBuffer cleartextChunk, long chunkNumber, FileHeader header)
Encrypts a single chunk of cleartext.void
encryptChunk(ByteBuffer cleartextChunk, ByteBuffer ciphertextChunk, long chunkNumber, FileHeader header)
Encrypts a single chunk of cleartext.
-
-
-
Method Detail
-
canSkipAuthentication
boolean canSkipAuthentication()
- Returns:
true
if 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 betrue
by default.- Returns:
- Decrypted content. Position is set to
0
and limit to the end of the chunk. - Throws:
AuthenticationFailedException
- If authenticate istrue
and the given chunk does not match its MAC.UnsupportedOperationException
- If authenticate isfalse
but 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 betrue
by default.- Throws:
AuthenticationFailedException
- If authenticate istrue
and the given chunk does not match its MAC.UnsupportedOperationException
- If authenticate isfalse
but 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.
-
-