Interface FileContentCryptor


  • public interface FileContentCryptor
    • 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 encrypted
        chunkNumber - Number of the chunk to be encrypted
        header - 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 encrypted
        ciphertextChunk - Encrypted content buffer (with at least ciphertextChunkSize() remaining bytes)
        chunkNumber - Number of the chunk to be encrypted
        header - 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 decrypted
        chunkNumber - Number of the chunk to be decrypted
        header - Header of the file, this chunk belongs to
        authenticate - Skip authentication by setting this flag to false. Should always be true by default.
        Returns:
        Decrypted content. Position is set to 0 and limit to the end of the chunk.
        Throws:
        AuthenticationFailedException - If authenticate is true and the given chunk does not match its MAC.
        UnsupportedOperationException - If authenticate is false but this cryptor can 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 the length of the header.
        Returns:
        Cleartext length of a ciphertextSize-sized ciphertext decrypted with cryptor.
      • 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 with cryptor. Not including the length of the header.