Encrypt
(Engine-Level Function)
Description: |
The Encrypt function encrypts data. The algorithm used to encrypt the data is designated by the Key parameter. It is the VTScada analog of the Windows CryptoAPI CryptEncrypt call. Encrypt fully supports asymmetric and symmetric keys via CNG (Cryptography New Generation). |
Returns: | Text |
Usage: | Script Only. |
Function Groups: | Cryptography |
Related to: | DeriveKey | Decrypt | Encrypt | ExportKey | GenerateKey | GetCryptoProvider | GetKeyParam | ImportKey | SetKeyParam |
Format: | Encrypt(Key, PlainText, Final [, Reserved, Flags, Error]) |
Parameters: |
Key | ||||||||||||||||
Required. The handle to the key to use to encrypt the data. | ||||||||||||||||
PlainText | ||||||||||||||||
Required. A text string that contains the plain text to be encrypted. | ||||||||||||||||
Final | ||||||||||||||||
Required. A parameter that specifies whether this is the last section in a series being encrypted. Final is set TRUE for the last or only block and FALSE if there are more blocks to be encrypted |
||||||||||||||||
Reserved | ||||||||||||||||
An optional parameter that should be set to 0. If omitted or invalid, then the value 0 is used. | ||||||||||||||||
Flags | ||||||||||||||||
Optional. Specifies the flags to be passed to CryptEncrypt. If omitted or invalid then the value 0 is used. Refer to the Crypto API Encrypt function for the flag list if using CAPI. If using a CNG key, the following may be used (separate tables provided for asymmetric and symmetric keys) If the encryption key is an asymmetric key:
If the encryption key is a symmetric key:
|
||||||||||||||||
Error | ||||||||||||||||
Optional. A variable in which the error code for the function is returned. It has the following meaning: (no default)
|
Comments: |
The cipher text is returned as a text string. If an error occurs, the return value is invalid. When using CNG keys, the data supplied to Encrypt must be an integer multiple of the symmetric key block size UNLESS Flags is set to one of the padding options, when the algorithm will automatically pad the plaintext as required. Note that the size of a block can be obtained using the GetKeyParam function and specifying the "BlockLength" property. |
Example:
[ PlainText1 = "abcdefghijklmnopqrstuvwxyz0123456789"; CipherText1; ] Init [ If 1 Main; [ CipherText1 = Encrypt(Key3, PlainText1, 1, 0, 0); ] ]