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______________________
|