Indy 9
TIdBlockCipherIntercept
Hierarchy, Properties, Methods, Events, See Also, Unit: IdBlockCipherIntercept
Implements an Indy intercept for encryption and decryption of data blocks.
TIdBlockCipherIntercept = class(TIdConnectionIntercept)
Unit
IdBlockCipherIntercept
Description
TIdBlockCipherIntercept is a TIdConnectionIntercept descendant that implements an Indy intercept for encryption and decryption of blocks of data using a specified block size. TIdBlockCipherIntercept overrides the inherited Send and Receive methods to allow encyption of block data prior to transmission, and decryption of block data after receipt. TIdBlockCipherIntercept also implements the OnReceive and OnSend event handlers to provide access to external encryption and decryption routines.

TIdBlockCipherIntercept.BlockSize
TIdBlockCipherIntercept, See Also
Indicates the number of bytes to handle in decryption/encryption in Send or Receive operations.
property BlockSize: Integer;
Description
BlockSize is an integer property that indicates the number of bytes to handle in Send or Receive operations. BlockSize is the number of bytes extracted from the output buffer in Send, and passed to the Encrypt method. BlockSize is also the number of bytes extracted from the input buffer in Receive, and passed to the Decrypt method.

BlockSize is used to determine when an EIdBlockCipherInterceptException exception shopuld be raised when a block exceeeds the indicated value.

The default value for BlockSize is IdBlockCipherBlockSizeDefault as assigned in the Create constructor.

BlockSize can be changed at runtime as long as the new block size value is greater than 0 and does not exceed IdBlockCipherBlockSizeMax. ANy change to the value in BlockSize outside this acceptable range is ignored.


TIdBlockCipherIntercept.Data
TIdBlockCipherIntercept, See Also
Provides access to cipher-specific data required for encryption or decryption algorithms.
property Data: TObject;
Description
Data is a Pointer property used to provide cipher-specific data to the OnSend and OnReceive event handlers. Data can be used to store a pointer to any record, data type, or class instance required by the encryption or decryption alogrithms implemented in these event handlers.

Data is set to the corresponding property value from the TIdBlockCipherIntercept passed as an argument in CopySettingsFrom.

Note: Data is not maintained by the Create or Destroy methods. Applications must provide memory and/or resource protection required to initailize and free the contents of the Data property.


TIdBlockCipherIntercept.CopySettingsFrom
TIdBlockCipherIntercept, See Also
Initializes a block intercept using property values from another block intercept instance.
procedure CopySettingsFrom(ASrcBlockCipherIntercept: TIdBlockCipherIntercept);
Parameters
ASrcBlockCipherIntercept: TIdBlockCipherIntercept
Object instance containing properties to be used for the current object instance.
Description
CopySettingsFrom is a procedure used to initialize a block intercept using values from another block intercept instance. ASrcBlockCipherIntercept is the block intercept to be used as the source for initializing properties in the object instance. CopySettingsFrom will set the following properties and event handlers to the values in ASrcBlockCipherIntercept:


TIdBlockCipherIntercept.Create
TIdBlockCipherIntercept, See Also
Constructor for the object instance.
constructor Create(AOwner: TComponent); override;
Parameters
AOwner: TComponent
Owner of the object instance.
Description
Create is the constructor for the object instance. Create calls the inherited Create method using AOwner as the owner of the object instance. Create also sets the BlockSize property to its default value IdBlockCipherBlockSizeDefault. Create also allocates resources required for the internal TMemoryStream buffers used in Send and Receive.

TIdBlockCipherIntercept.Destroy
TIdBlockCipherIntercept, See Also
Frees the object instance.
destructor Destroy; override;
Description
Destroy is the destructor for the object instance. Destroy frees resources allocated to the internal Send and Receive buffers. Destroy calls the inherited Destroy method prior to exiting.

TIdBlockCipherIntercept.Receive
TIdBlockCipherIntercept, See Also
Decrypts received data for the block intercept.
procedure Receive(ABuffer: TStream); override;
Parameters
ABuffer: TStream
Stream containing the encrypted values, and decrypted bytes after Receive.
Description
Receive is an overidden procedure in TIdBlockCipherIntercept that implements decrypting a stream-based receive buffer for the block intercept instance. ABuffer is the TStream containing the initial encrypted receive buffer contents for the operation, and the transformed values after the Receive operation. Receive appends the contents of ABuffer to the internal receive buffer, and sets the current position to the beginning of the internal buffer prior to processing its contents.

The Receive method will exit immediately if the size of the internal buffer is zero (or a negative number).

Receive attempts to read and process blocks of data from the internal receive buffer, using BlockSize as the size of each data block. Receive will continue to read and process data blocks until all data has been read, or the remaining content in the internal receive buffer is smaller than BlockSize. Specifics of the decryption algorithm can be implemented using the OnReceive event handler and the CipherData property.

If a block is read from the internal buffer that is larger than BlockSize, an EIdBlockCipherInterceptException will be raised.

Receive calls the protected virtual Decrypt method for each data block read from the internal receive buffer. Unprocessed bytes from the buffer smaller than BlockSize bytes are cached in the internal receive buffer for subsequent Receive operations. The internal receive buffer is truncated to the number of unprocessed bytes remaining.

The decrypted values for all data blocks are returned in the ABuffer argument, and the length of ABuffer is set to the number of decrypted bytes returned to the stream.


TIdBlockCipherIntercept.Send
TIdBlockCipherIntercept, See Also
Encrypts data for the block intercept prior to transmission.
procedure Send(ABuffer: TStream); override;
Parameters
ABuffer: TStream
Stream containing the unencrypted values, and encrypted bytes after Send.
Description
Send is an overridden procedure in TIdBlockCipherIntercept that implements encrypting a stream-based send buffer for the block intercept instance. ABuffer is the TStream containing the initial values to be encrypted during the operation, and the transformed values after the Send operation. Send loads the contents of ABuffer to the internal send buffer, and sets the current position to the beginning of the internal buffer prior to processing its contents.

The Send method will exit immediately if the size of the internal buffer is zero (or a negative number).

Send attempts to read and process blocks of data from the internal send buffer, using BlockSize as the size for each data block. Send will continue to read and process data blocks until all data has been read, or the remaining content in the internal send buffer is smaller than BlockSize. Unprocessed bytes from the buffer smaller than BlockSize bytes are read from the buffer, padded to the length indicated in BlockSize, and Encrypted to complete the transformation of data. Specifics of the encryption algorithm can be implemented using the OnSend event handler and the CipherData property.

Send calls the protected virtual Encrypt method for each data block in the internal Send buffer. The encrypted values for all data blocks are returned in the ABuffer argument, and the length of ABuffer is set to the number of encrypted bytes returned to the stream.


TIdBlockCipherIntercept.OnReceive
TIdBlockCipherIntercept, See Also
Implements access to a decryption algorithm for the block intercept.
property OnReceive: TIdBlockCipherInterceptDataEvent;
Parameters
ADstData
Pointer to data after transformation.
ASender
Block intercept for the event notification.
ASrcData
Pointer to data to use as input for the transformation.
Description
OnReceive is a TIdBlockCipherInterceptDataEvent property that represents the event handler triggered when the block intercept needs to use it's decryption algorithm to transform received data. OnReceive is used, along with the Data property, to provide access to the decryption algorithm implemented for the block intercept instance.

ASender is the TIdBlockCipherIntercept instance for the event notification.

ASrcData is a Pointer to the encrypted data to use as input for the transformation.

ADstData is a Pointer to the unencrypted data after transformation.

Applications must assign a procedure to the event handler to allow implementation of a specific decryption algorithm, and to perform data transformation.

Use OnSend to implement the encryption algorithm used for the block intercept.


TIdBlockCipherIntercept.OnSend
TIdBlockCipherIntercept, See Also
Implements access to a decryption algorithm for the block intercept.
Parameters
ADstData
Pointer to data after transformation.
ASender
Block intercept for the event notification.
ASrcData
Pointer to data to use as input for the transformation.
Description
OnSend is a TIdBlockCipherInterceptDataEvent property that represents the event handler triggered when the block intercept needs to use it's encryption algorithm to transform data prior to transmission. OnSend is used, along with the CipherData property, to provide access to the encryption algorithm implemented for the block intercept instance.

ASender is the TIdBlockCipherIntercept instance for the event notification.

ASrcData is a Pointer to the unencrypted data to use as input for the transformation.

ADstData is a Pointer to the encrypted data after transformation.

Applications must assign a procedure to the event handler to allow implementation of a specific encryption algorithm, and to perform data transformation.

Use OnReceive to implement the decryption algorithm used for the block intercept.


Created with Doc-O-Matic 2 donated to Project JEDI. Commercial license available from the Doc-O-Matic site.