Crypto Failure Trying to Create Container.

Discussion in 'Windows Vista Help' started by DrShell, Sep 17, 2010.

  1. DrShell

    DrShell Guest

    I hope someone here can help me on this...if not, please direct me to
    a group that can.

    I've developed a VB6 program that uses the Windows Cryptographic
    Provider in Win2K. In it's upgrades I've taken it up through XP and
    into Vista. It was, until Vista, a very stable program. Now it fails
    to create the Key Container. I've had the user run in Administrator
    to attempt to give the program the authority it needs to do this, but
    it still fails.

    Can someone take a look at my code and see if there is anything wrong?
    Thanks in advance for any help.

    The following code assumes that:
    abKeyCon is a Byte Array with the Container name
    abSerPro is a Byte Array with the value
    "Microsoft Enhanced Cryptographic Provider v1.0"

    Watch for line wrap ;-)

    _____________Code Start_____________________________
    Public Property Let KeyContainerName(strKeyConName As String)
    lngLastError = 0
    If Len(strKeyConName) > 0 Then
    ReDim abKeyCon(Len(strKeyConName))
    abKeyCon = StrConv(strKeyConName, vbFromUnicode) & vbNullChar
    Else
    ReDim abKeyCon(0)
    abKeyCon(0) = vbNullChar
    End If
    End Property

    Public Sub SessionEnd()
    If hSessionKey <> 0 Then CryptDestroyKey hSessionKey
    If hKeyPair <> 0 Then CryptDestroyKey hKeyPair
    If hCryptProv <> 0 Then CryptReleaseContext hCryptProv, 0
    End Sub

    Public Function SessionStart(Optional sKeyCon As String, Optional
    bFresh As Boolean = False) As Boolean
    Dim lngReturnValue As Long
    SessionEnd
    lngLastError = 0
    KeyContainerName = sKeyCon
    If bFresh Then
    lngReturnValue = CryptAcquireContext( _
    hCryptProv, abKeyCon(0), abSerPro(0), PROV_RSA_FULL,
    CRYPT_DELETEKEYSET _
    )
    If lngReturnValue = 0 Then Err.Clear
    lngReturnValue = CryptAcquireContext( _
    hCryptProv, abKeyCon(0), abSerPro(0), PROV_RSA_FULL,
    CRYPT_NEWKEYSET _
    )
    If lngReturnValue = 0 Then
    lngLastError = Err.LastDllError
    Exit Function
    End If
    Else
    lngReturnValue = CryptAcquireContext( _
    hCryptProv, abKeyCon(0), abSerPro(0), PROV_RSA_FULL,
    CRYPT_EXISTINGKEYSET _
    )
    If lngReturnValue = 0 Then
    Err.Clear
    lngReturnValue = CryptAcquireContext( _
    hCryptProv, abKeyCon(0), abSerPro(0), PROV_RSA_FULL,
    CRYPT_NEWKEYSET _
    )
    If lngReturnValue = 0 Then
    lngLastError = Err.LastDllError
    Exit Function
    End If
    End If
    End If
    SessionStart = True
    End Function
    __________________________End Code______________________
     
    DrShell, Sep 17, 2010
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.