Decrypt

(Engine-Level Function)

Description:

The Decrypt function decrypts data previously encrypted using the Encrypt function. It is the VTScada analog of the CryptoAPI CryptDecrypt call.

Decrypt fully supports asymmetric and symmetric keys via CNG (Cryptography New Generation)

Returns: Text
Usage: Script Only.
Function Groups: Cryptography
Related to: DeriveKey | Encrypt | ExportKey | GenerateKey | GetCryptoProvider | GetKeyParam | ImportKey | SetKeyParam
Format: Decrypt(Key, CipherText, Final [, Reserved, Flags, Error])
Parameters:  
Key   
Required. The handle to the key to use to decrypt the data.
CipherText   
Required. A text string that contains the cipher text to be decrypted.
Final    
Required. A parameter that specifies whether this is the last section in a series being decrypted. Final is set TRUE for the last or only block and FALSE if there are more blocks to be decrypted
Reserved n/a
An optional parameter which should be set to 0. If omitted or invalid, then the value 0 is used.
Flags   

Optional. An optional parameter specifying the flags to be passed to CryptDecrypt. If omitted or invalid then the value 0 is used.

When using a CNG key, the Flags parameter can take the same values as for Encrypt.

Error   
Required. An optional variable in which the error code for the function is returned. It can have the following meanings:

Value

Meaning

0

Key successfully imported.

1

Key, CipherText or Final parameters invalid.

x

Any other value is an error from CryptDecrypt.

Comments: The plain text is returned as a text string. If an error occurs, the return value is invalid.

Example:

[
  PlainText2; 
]
Init [
  If 1 Main; 
  [ 
    PlainText2 = Decrypt(Key4, CipherText1, 1, 0, 0); 
  ] 
]