Xceed Encryption Library Documentation
Encrypt method
Xceed Encryption control reference > Methods > Encrypt method

Description

The Encrypt method encrypts data entirely in memory. It can encrypt data in a single call, or it can be called multiple times to encrypt data in a streaming fashion.

Parameters
 

Parameter Description
vaSource  The data to encrypt. All OLE automation variant types are supported, including string and byte array variants.
 
bEndOfData  This parameter indicates to the library whether or not there is more data to encrypt.

If you only have a single block of data to encrypt, set this parameter to True. The library will then immediately encrypt all the data provided in the vaSourceparameter and return the resulting encrypted data.

 

If you can only provide a portion of the data to encrypt in the vaSourceparameter and will provide more data later in a subsequent call to the Encrypt method, set this parameter to False. In this case, the library will encrypt and return as much data as possible. When the final portion of the data to encrypt has been provided, set the bEndOfData parameter to True. The method will then return the final portion of the encrypted data.

Return value

The return value is a byte array variant containing the encrypted data.

Associated properties

These properties can be found in the various Encryption Method objects.

EncryptionMethod, EncryptionMode, InitVector, PaddingMethod, SecretKey, PublicKey

Associated methods

ToString and FromString

Remarks

For secret-key encryption the SecretKey property must be initialized and, if the EncryptionMode property is set to emoChainedBlocks the InitVector property must be initialized.

For public-key encryption , the PublicKey property must be initialized and must have a strength of at least 338 bits.

When calling the Encrypt method with the bEndOfData parameter specified as False, you cannot call any other Xceed Encryption control method (of the same instance of the control) until you have completed processing a stream of data by calling the Encrypt method with the bEndOfData parameter specified as True, or an error occurs, or the Reset method is called.

When encrypting with a secret-key encryption algorithm, the library may automatically pad the last encrypted block with a fixed value (the value used corresponds to the number of bytes padded). The PaddingMethod property determines exactly how padding will be performed. When decrypting, the library will make sure that these padding characters are recognized and ignored. This padding scheme implies that there may be an additional block at the end of the encrypted data stream containing bytes of all the same plain text value (usually 16).

Language-specific remarks

With Visual Basic, it is often necessary to convert the resulting encrypted data from a byte array variant to a native VB byte array before saving it or transmitting it. VB6 makes it particularly easy to do the conversion: If you have a variant named (for example) EncryptedData, you can convert it to a native VB byte array with the following code:

Visual Basic Copy Code

Dim EncryptedDataArray() As Byte
EncryptedDataArray = EncryptedData

With Microsoft Access, you can place the encrypted data in either a Memo field or an OLE Object field. Using an OLE Object field in a table is the easiest: You can directly assign your data to the field and conversion is automatic. To assign the encrypted data variant to a Memo field, use the "AppendChunk" function in Access.

Declaration (DXceedEncryption) Copy Code
HRESULT Encrypt( [in] VARIANT* vaSource, [in] VARIANT_BOOL bEndOfData,
                 [retval][out] VARIANT* vaEncrypted )
Declaration (IXceedEncryption) Copy Code

HRESULT Encrypt( [size_is][in] BYTE* pcSource, [in] DWORD dwSourceSize, [in] BOOL bEndOfData,
                 [size_is][size_is][out] BYTE** ppcEncrypted, [out] DWORD* pdwEncryptedSize )