Generates a session key from the Cryptographic Service Provider (CSP) and exports the session key BLOB to a file.
Syntax:
<lretval> = object.GenerateSessionKey(<sExportFileName>, [<sKeyContainer>], [<sServiceProvider>], [<lProviderType>])
Parameters:
Returns
Returns 1 if the operation is successful; otherwise returns 0 if the operation fails.
Remarks
A random session key is generated from the CSP, and is encrypted using the key from the destination user, so that only the destination user can use the session key. The encrypted key BLOB is extracted from the CSP and is then saved to a file. The algorithm used to encrypt the session key is CALG_RC4 only if the CSP supports it, otherwise another encryption algorithm supported by the CSP will be selected. If the CSP does not support any encryption algorithm, an error will be generated and this method fails.
The sServiceProvider and lProviderType specify the CSP that has the key container. If sServiceProvider and/or lProviderType are not specified, the default CSP database is used, which is specified by DefaultProviderName andServiceProviderType. The type of database, whether machine key set or user key set, is specified using ediDocument.Option by the constant OptDocument_MachineKeySet.
Example:
Dim oEdiDoc As Fredi.ediDocument
Dim oSecurities As Fredi.ediSecurities
Dim sSessKeyFile As String
' Create instance of Framework EDI.
Set oEdiDoc = New Fredi.ediDocument
' Get the securities object
Set oSecurities = oEdiDoc.GetSecurities
' Set Cryptographic Service Provider default.
oSecurities.DefaultProviderName = "Microsoft Enhanced Cryptographic Provider v1.0"
' Session key file.
sSessKeyFile = App.Path & "\MySessionKey.BIN"
' Generate session key
If oSecurities.GenerateSessionKey(sSessKeyFile) = 1 Then
MsgBox "Successfully generated session key to '" & sSessKeyFile & "'."Else
MsgBox "Failed to generate session key."End If
Sample