GetCryptoProvider

Purpose:                    The GetCryptoProvider function is used to acquire a handle to a particular key container within a particular cryptographic service provider (CSP). This returned handle can then be used to make calls to the selected CSP. It is the VTS analog of the CryptoAPI CryptAcquireContext call.

Returns:                    Handle

Usage:                       Script

Format:                      GetCryptoProvider(CSPType [, CSPName, ContainerName, Flags, Error])

Parameters:             CSPType   { numeric }  { required }  { no default }

                                              The type of CSP required. Values are defined in WinCrypt.h.

                                    CSPName   { text }  { optional }  { default: see note }

                                              An optional parameter that holds the name of the required CSP. If omitted or invalid, then a handle to the default CSP of the specified type will be acquired.

                                    ContainerName   { text }  { optional }  { default: see note }

                                              An optional parameter that holds the name of the key container. If omitted or invalid, then the default key container for the CSP is used.

                                    Flags   { numeric }  { optional }  { default: 0 }

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

                                    Error   { numeric }  { optional }  { no default }

                                              An optional variable in which the error code for the function is returned. It has the following meaning:

Error

Meaning

0

CSP handle successfully returned.

1

CSPType parameter invalid.

x

Any other value is an error from CryptAcquireContext.

 

Comments:               The return value for this function is a handle to the CSP. If an error occurs, then the return value is invalid. A CSP handle has a value type of 36. If cast to text then the name of the CSP will be returned.

                             If ContainerName is omitted or invalid then a default key container name is used. For example, the Microsoft Base Cryptographic Provider uses the logon name of the user currently logged on as the key container name. Other CSPs can also have default key containers that can be acquired in this way.

Example:

[

  CSP; 

  CSPFail; 

  Container = "VTS"; 

  Constant PROV_DSS_DH = 13; 

  Constant CRYPT_NEWKEYSET = 8; 

  Constant NTE_BAD_KEYSET = 0x80090016; 

]

Init [

  If 1 Main; 

  [ 

    CSP = GetCryptoProvider(PROV_DSS_DH, Invalid,

                            Container, Invalid, CSPFail); 

    IfThen(CSPFail == NTE_BAD_KEYSET, 

       { Not used this container before, make a new one } 

       CSP = GetCryptoProvider(PROV_DSS_DH, Invalid,

                            Container, CRYPT_NEWKEYSET, CSPFail); 

    ); 

  ] 

]

See Also:

DeriveKey | Decrypt | Encrypt | ExportKey | GenerateKey | GetKeyParam | ImportKey | SetKeyParam