ICipher interface
Contents
- Introduction to the Library
- Basic support package (com.kryptel.bslx)
- Kryptel API Commons package (com.kryptel)
- Cipher package (com.kryptel.cipher)
- Compressor package (com.kryptel.compressor)
- Exceptions package (com.kryptel.exceptions)
- Hash function package (com.kryptel.hash_function)
- MAC function package (com.kryptel.mac)
- Key-related functions (com.kryptel.key)
- Silver Key engine (com.kryptel.silver_key)
- Kryptel encrypted storage (com.kryptel.storage)
Declaration
package com.kryptel.cipher; import com.kryptel.IDataSink; public interface ICipher { void Init(IDataSink callback, Object arg) throws Exception; void Encrypt(byte[] src, int start, int size) throws Exception; void Decrypt(byte[] src, int start, int size) throws Exception; void Done() throws Exception; }
Description
The primary cipher interface, which allows encryption (or decryption) of arbitrary length data. The interface performs decoration of the data stream as described in the Encrypted Stream article. Encrypt and Decrypt calls are mutually exclusive and can't be mixed within the same Init-Done sequence. For example, if the first call is Encrypt, then no Decrypt call will be allowed until Done and another Init.
See an example of file encryption using ICipher.
Init
void Init(IDataSink callback, Object arg) throws Exception;
Initializes the cipher and prepares it for a new session. The next Encrypt or Decrypt call determines the type of the operation (i.e. encryption or decryption).
- callback
- The data sink interface to which the output data will be sent.
- arg
- This argument is passed to IDataSink.Init. It usually contains a link to an object, which will receive the output stream (for example, a file).
Encrypt
void Encrypt(byte[] src, int start, int size) throws Exception;
Encrypt size bytes of data in src at position start. The result will be sent to the data sink interface specified in the starting Init call. Note that because of buffering the encryption operation will not necessarily cause any output, or may cause output of a block much larger than the block being encrypted.
Decrypt
void Decrypt(byte[] src, int start, int size) throws Exception;
Decrypt size bytes of data in src at position start. The decrypted data will be sent to the data sink interface specified in the starting Init call. As with the Encrypt method, the data output very loosely depends on this function calls.
Done
void Done() throws Exception;
Finishes processing, flushes buffers, and resets the cipher to the idle state.