GenerateKey
(Engine-Level Function)
| Description: | The GenerateKey function generates a random cryptographic session key or a public/private key pair. A handle to the key or key pair is returned. This handle can then be used as needed with any CryptoAPI function requiring a key handle. It is the VTScada analog of the CryptoAPI’s CryptGenKey call. |
| Returns: | Handle |
Usage: ![]() |
Script Only. |
| Function Groups: | Cryptography |
| Related to: | DeriveKey | Decrypt | Encrypt | ExportKey | GenerateKey| GetKeyParam | ImportKey | SetKeyParam | Data Encryption and Decryption |
Format: ![]() |
GenerateKey(CSPHandle, AlgID [, Flags, Error]) |
| Parameters: |
| CSPHandle | ||||||||
| Required. The handle of a CSP (cryptographic service provider) to use to generate the key. | ||||||||
| AlgID | ||||||||
| Required. Identifies the algorithm for which the key is to be generated. Values for this parameter vary depending on the CSP used and are defined in WinCrypt.h | ||||||||
| Flags | ||||||||
| An optional parameter specifying the flags to be passed to CryptGenKey. If omitted or invalid then the value 0 is used. | ||||||||
| Error | ||||||||
An optional variable in which the error code for the function is returned. It can have the following values.
|
| Comments: |
The return value for this function is a handle to the Key. If an error occurs, then the return value is invalid. A key has a value type of 37. If cast to text, then the hexadecimal value of the algorithm ID will be returned. Does not support CNG (Cryptography New Generation). |
Example:
[
Key1;
Key2;
Constant CALG_DH_EPHEM = 0xAA02;
Constant KEY_SIZE = 512;
Constant CRYPT_EXPORTABLE = 0x00000001;
]
Init [
If 1 Main;
[
{ Make a key }
Key1 = GenerateKey(CSP, CALG_DH_EPHEM,
KEY_SIZE << 16 || CRYPT_EXPORTABLE );
]
]
