Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista Help > Crypto Failure Trying to Create Container.

Reply
Thread Tools Display Modes

Crypto Failure Trying to Create Container.

 
 
DrShell
Guest
Posts: n/a

 
      09-17-2010
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______________________
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SBS 2008 console unable to create new Distribution Groups Glenn_Thomas Windows Small Business Server 2 02-17-2010 03:57 AM
How to create video for WEB? wbardo Windows Vista Music, Pictures and Video 0 01-15-2010 01:50 PM
Re: Pre-authentication events logged, but not lock-out or auth failure Paul Bergson [MVP-DS] Active Directory 0 11-04-2009 12:36 PM
Re: Pre-authentication events logged, but not lock-out or auth failure Jorge Silva Active Directory 0 11-03-2009 03:43 PM
cloning laptop sata harddrive vista premium Mark Ryan Windows Vista Hardware 5 04-26-2007 06:44 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59