Interface IFinCipherAlgorithm

Namespace
Subsembly.FinTS
Assembly
Subsembly.FinTS.Core.dll

Provides the cipher algorithm to the Encrypt(byte[], IFinCipherAlgorithm) and Decrypt(byte[], IFinCipherAlgorithm) methods.

public interface IFinCipherAlgorithm

Methods

Decrypt(byte[], byte[], int, int)

Decrypts the entire data buffer in place.

int Decrypt(byte[] vbSessionKey, byte[] vbData, int nOffset, int nLength)

Parameters

vbSessionKey byte[]

Session key to be used for decrypting the data. Must not be null.

vbData byte[]

Data buffer that contains encrypted data to be decrypted. The data in this buffer will be replaced by the decrypted data. Must not be null.

nOffset int

Offset of first byte in buffer to be decrypted.

nLength int

Byte length of data starting at nOffset in vbData.

Returns

int

Returns the original unpadded byte length of the decrypted data.

Remarks

The data buffer is assumed to contain the encrypted data including its padding. After decrypting the data, the return value provides the original unpadded byte length of the data.

Exceptions

ArgumentNullException

Either parameter was null.

ArgumentOutOfRangeException

The offset, or the length were outside the provided buffer.

FinSecurityException

If the aSessionKey has the wrong size or is unacceptable for other reasons, then a FinSecurityException with code BadSessionKey is thrown. Such exception probably indicates that the session key was not decrypted successfully.

If the provided data is not of appropriate length, or the resulting decrypted data is garbage, then a FinSecurityException with code DecryptFailure is thrown. Note that the absence of such exception does not mean that the data was indeed decrypted successfully!

Encrypt(byte[], byte[], int, int)

Encrypts the entire data buffer in place.

int Encrypt(byte[] vbSessionKey, byte[] vbData, int nOffset, int nLength)

Parameters

vbSessionKey byte[]

Session key to be used for encrypting the data. Must not be null.

vbData byte[]

Data buffer that contains plain data to be encrypted. The data in this buffer will be replaced by the padded and encrypted data. Must not be null. The buffer must be large enough to hold the PaddedLength(int) of the given data length.

nOffset int

Offset of first byte in buffer to be encrypted.

nLength int

Unpadded byte length of data starting at nOffset in vbData.

Returns

int

Remarks

The provided buffer will be used beyond the given nLength in order to accomodate any padding required by the cipher algorithm. Therefore, the caller must use PaddedLength(int) in order to create a buffer with sufficient capacity.

Exceptions

ArgumentNullException

Either parameter was null.

ArgumentOutOfRangeException

The offset, the length or padded length were outside the provided buffer.

FinSecurityException

If the aSessionKey has the wrong size or is unacceptable for other reasons, then a FinSecurityException with code BadSessionKey is thrown. Such exception usually means that the caller did not provide a session key originally created by GenerateSessionKey().

GenerateSessionKey()

Generates a new session key suitable for subsequent encryption.

byte[] GenerateSessionKey()

Returns

byte[]

The generated session key.

PaddedLength(int)

Computes the padded length of the encrypted data based on the plain data length.

int PaddedLength(int nLength)

Parameters

nLength int

Plain unencrypted byte length of the data that shall be encrypted.

Returns

int

The byte length that is required in order to hold the padded and encrypted data of the given length.

Exceptions

ArgumentOutOfRangeException

The given nLength was negative.