PC Review


Reply
Thread Tools Rate Thread

CryptAcquireContext Lib "advapi32"

 
 
Stephen Rasey
Guest
Posts: n/a
 
      23rd Dec 2006
I have a new computer in which I installed Office 2003, then Office 2007,
retaining the 2003 programs.

An Excel application I use has a set of user functions that make use of the
CryptAcquireContext and CryptCreateHash funtions to create a hash on a set
of Excel Ranges. The purpose is to create a unique, single cell value to
identifiy whether any changes have been made to several hundred cells used
as hash input.

In this new computer, the CryptAcquireContext is returning zero, not some
random-type long integer.

My guess is that I have an incorrect advapi32.dll installed, or Excel is
confused where to look for it. The two versions of Excel installed might
have caused the confusion.
Currently, there are 4 copies of advape32.dll on this computer:
<pre>
C:\Windows\system32 603 KB 3/15/2006
C:\SWSetup\MSM2006S\IE\Setupw95.cab 41KB 8/29/2002
C:\Program Files\Online services\PeoplePC\IE\EN\SetupW95.CAB 41KB
8/29/2002
C:\SWSetup\MSWorks\US\REDIST\IE6\SETUPW95.CAB 41KB
8/29/2002
</pre>
I have performed a repair on the Office 2003

Before I un-install everything and try things one at a time, I want to ask
if anyone has some simple fix to suggest.

'a Hash Function from Stephen Bullen.
'From: Stephen Bullen ((E-Mail Removed))
'Subject: Re: Hash (MD5) in Excel
'Newsgroups: microsoft.public.Excel.programming Date: 2004-02-05
12:50:20 PST
'Modified (bug fix) by Stephen Rasey June 2004

Option Explicit

Declare Function CryptAcquireContext Lib "advapi32" Alias
"CryptAcquireContextA" (ByRef hProv As Long, ByVal sContainer As String, _
ByVal sProvider As String, ByVal lProvType As Long, ByVal lFlags As
Long) As Long

Declare Function CryptCreateHash Lib "advapi32" (ByVal hProv As Long, ByVal
lALG_ID As Long, _
ByVal hKey As Long, ByVal
lFlags As Long, ByRef hhash As Long) As Long

Declare Function CryptHashData Lib "advapi32" (ByVal hhash As Long, ByVal
lDataPtr As Long, ByVal lLen As Long, ByVal lFlags As Long) As Long

Declare Function CryptGetHashParam Lib "advapi32" (ByVal hhash As Long,
ByVal lParam As Long, ByVal sBuffer As String, _
ByRef lLen As Long, ByVal
lFlags As Long) As Long

Declare Function CryptDestroyHash Lib "advapi32" (ByVal hhash As Long) As
Long

Declare Function CryptReleaseContext Lib "advapi32" (ByVal hProv As Long,
ByVal lFlags As Long) As Long

Const MS_DEF_PROV = "Microsoft Base Cryptographic Provider v1.0"
Const PROV_RSA_FULL As Long = 1
Const CRYPT_NEWKEYSET As Long = 8
Const CALG_MD5 As Long = 32771
Const HP_HASHVAL As Long = 2



' wwGetMD5Hash - GetMD5Hash (written by Stephen Bullen) modified by
Stephen Rasey 040612
' Changes: Use StrPtr and coerse all cell values to strings
' Empty cells are not ignored, but the cell number in the
range
' is used to generate more data for the hash

Public Function wwGetMD5Hash(rngData As Range) As String

Dim hProv As Long
Dim hhash As Long
Dim lLen As Long
Dim ocell As Range
Dim baData() As Byte
Dim sBuffer As String
Dim vValue As String
Dim vU2 As Variant
Dim lresult As Long
Dim lcellCounter As Long
On Error GoTo E1
'Get/create a cryptography context
CryptAcquireContext hProv, vbNullString, MS_DEF_PROV, PROV_RSA_FULL, 0
If hProv = 0 Then
CryptAcquireContext hProv, vbNullString, MS_DEF_PROV, PROV_RSA_FULL,
CRYPT_NEWKEYSET
End If

'If we got one...
If hProv <> 0 Then

'Create an MD5 Hash
CryptCreateHash hProv, CALG_MD5, 0, 0, hhash

'If that was OK...
If hhash <> 0 Then

'Fill it with the contents of the range
(and it continues...)
the full function can be found here:
http://www.excelsig.org/VBA/wwHash.htm

-Stephen Rasey


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
Hashing function CryptAcquireContext Lib "advapi32" not working in new computer. Stephen Rasey Microsoft Excel Programming 5 25th Dec 2006 04:05 AM
apiGetUserName Lib "advapi32.dll" =?Utf-8?B?TWU=?= Microsoft Access Form Coding 6 11th Aug 2006 07:50 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM
How to reboot local machine in c# using InitiateSystemShutdown(...) ---a function in "advapi32.dll" mrzt Microsoft C# .NET 3 21st Sep 2003 08:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:12 PM.