ImportKey

(Engine-Level Function)

Description: The ImportKey function transfers a cryptographic key from a key BLOB into a CSP (cryptography service provider). It is the VTScada analog of the CryptoAPI’s ImportKey call.
Returns: Key
Usage: Script Only.
Function Groups: Cryptography
Related to: DeriveKey | Decrypt | Encrypt | ExportKey | GenerateKey | GetCryptoProvider | GetKeyParam | SetKeyParam
Format: ImportKey(CSP, BlobType, KeyBLOB [, DecryptKey, Flags, Error])
Parameters:  
CSP   
Required. The handle to the CSP which is receive the imported key.
BlobType   
Required. A parameter specifying the type of key BLOB to be imported. Values are defined in WinCrypt.h
KeyBLOB   
Required. Text string containing the KeyBLOB to be imported.
EncryptKey
An optional parameter containing a Key handle for a key to be used to encrypt the exported key so that it may only be encrypted by the destination user. If omitted or invalid, then the value NULL is used.
Flags
An optional parameter specifying the flags to be passed to CryptExportKey. 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 may have the following values:

Error

Meaning

0

Key successfully imported.

1

CSP, BlobType or KeyBLOB parameters invalid.

X

Any other value is an error from CryptImportKey.

Comments: The new key is returned as a Key handle. If an error occurs, the return value is invalid.

Example:

[
  Constant PUBLICKEYBLOB = 0x6; 
  Key3; 
]
Init [
  If 1 Main; 
  [ 
    { Import the public key } 
    Key3 = ImportKey(CSP, PUBLICKEYBLOB, PubKey1, Key2); 
  ] 
]