473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

CryptAcquireContext advapi32.d*ll Error

I have a block of code that encrypts passwords before storing them it
an access database. It works fine on my pc, however on my client they
get the following error on the last line of code when entering a
password.
Error - "run-time error '87' application-defined or object-defined
error"
Code Where Error is generated is the last line -
If lRes = 0 Then Err.Raise Err.LastDllError
I call the function using a simple call
txtUSERPWD_hash = HashString(txtUSERPWD)
Any idea why this is not working? I am assuming it may have something
to do with the way the pc is locked down.
I either need to fix this or come up with a differnt encryption scheme.
Thanks in advance..
Function HashString( _
ByVal Str As String, _
Optional ByVal Algorithm As HashAlgorithm = MD5) As String
'' THIS IS THE PASSWORD CRYPTO MODULE
Dim hCtx As Long
Dim hHash As Long
Dim lRes As Long
Dim lLen As Long
Dim lIdx As Long
Dim abData() As Byte
lRes = CryptAcquireContext(hCtx, vbNullString, _
vbNullString, PROV_RSA_FULL, 0)
If lRes <> 0 Then
lRes = CryptCreateHash(hCtx, Algorithm, 0, 0, hHash)
If lRes <> 0 Then
lRes = CryptHashData(hHash, ByVal Str, Len(Str), 0)
If lRes <> 0 Then
lRes = CryptGetHashParam(hHash, HP_HASHSIZE, lLen, 4, 0)
If lRes <> 0 Then
ReDim abData(0 To lLen - 1)
lRes = CryptGetHashParam(hHash, HP_HASHVAL, abData(0),
lLen, 0)
If lRes <> 0 Then
HashString = StrConv(abData, vbUnicode)
End If
End If
End If
CryptDestroyHash hHash
End If
End If
CryptReleaseContext hCtx, 0
If lRes = 0 Then Err.Raise Err.LastDllError
End Function
'-----------------------<< end code >>-----------------------
-----
The other block of code that has the delcare statements
Private Declare Function CryptAcquireContext Lib "advapi32.dll" _
Alias "CryptAcquireContextA" ( _
ByRef phProv As Long, _
ByVal pszContainer As String, _
ByVal pszProvider As String, _
ByVal dwProvType As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function CryptReleaseContext Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function CryptCreateHash Lib "advapi32.dll" ( _
ByVal hProv As Long, _
ByVal Algid As Long, _
ByVal hKey As Long, _
ByVal dwFlags As Long, _
ByRef phHash As Long) As Long
Private Declare Function CryptDestroyHash Lib "advapi32.dll" ( _
ByVal hHash As Long) As Long
Private Declare Function CryptHashData Lib "advapi32.dll" ( _
ByVal hHash As Long, _
pbData As Any, _
ByVal dwDataLen As Long, _
ByVal dwFlags As Long) As Long
Private Declare Function CryptGetHashParam Lib "advapi32.dll" ( _
ByVal hHash As Long, _
ByVal dwParam As Long, _
pbData As Any, _
pdwDataLen As Long, _
ByVal dwFlags As Long) As Long
Private Const PROV_RSA_FULL = 1
Private Const ALG_CLASS_HASH = 32768
Private Const ALG_TYPE_ANY = 0
Private Const ALG_SID_MD2 = 1
Private Const ALG_SID_MD4 = 2
Private Const ALG_SID_MD5 = 3
Private Const ALG_SID_SHA1 = 4
Enum HashAlgorithm
md2 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD2
md4 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD4
MD5 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_MD5
SHA1 = ALG_CLASS_HASH Or ALG_TYPE_ANY Or ALG_SID_SHA1
End Enum
Private Const HP_HASHVAL = 2
Private Const HP_HASHSIZE = 4

Jul 17 '05 #1
3 11130
Greg
2
I have the same problem. My application is working from two servers. On a third server it gets the "87 application-defined or object-defined error". I traced it a litter further to learn
CryptAcquireContext(hCtx, vbNullString, vbNullString, PROV_RSA_FULL, 0)
returns 0 which is an error condition. Any suggestions?
Sep 23 '05 #2
Greg
2
I found this posting which resolved the problem:

Had exactly the same problem - try this sorted it for me |

Firstly change
Private Const PROV_RSA_FULL = 1
to
Private Const PROV_RSA_FULL as Long = 1

Add a definition of :

Private Const CRYPT_VERIFYCONTEXT As Long = &HF0000000

Then change the call to CryptAcquireContext from
| lRes = CryptAcquireContext(hCtx, vbNullString, _
| vbNullString, PROV_RSA_FULL, 0)

To

|lRes = CryptAcquireContext(hCtx, vbNullString, _
vbNullString, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)

Seems that when the exe is running it does not cast the Constants to
longs correctly.

Hope this helps,

Mark
Sep 23 '05 #3
Hi...


Keep in mind, I don't know the specifics of what your environment is.

But, if you have a network authentication server, there is a 12(?) line solution that will gleen the network id out of the avapi file and then you just maintain a user table. Whenever they open the application let an AutoExec macro the functions, and presto...auto-authentication...using network pass-through authentication is easier for me, that way I can circumvent the brilliant minds in I.T. Let them maintain the authentication...if you are interested, I could post it...I don't have it with me at this moment...

Regards.

Hans
Sep 24 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dieter Schmitz | last post by:
Hi, I wrote a VB-Dll which uses the CryptAcquireContext function in the advapi32.dll. This works fine with VB, but when I use the same Dll in ASP the error number 0x800A0002 was returned when...
0
by: Alex Wolff | last post by:
Hello, I have the following snippet of code, which in VB gives me the current network login. I am trying to migrate the code to asp so I can use it from a web page. When I call my asp page the...
1
by: Blacksheep | last post by:
Can anyone help me with the following problem : I'm just trying to have the API call LogonUserA run correctly. Each run ends up with the following message : "The instruction at 0x77.. referenced...
1
by: schnitzell | last post by:
Hi, My problem is following: I my ActiveX I call the Crypt API method CryptAcquireContext and it is ok under all Windows platforms, but one - Windows 2003. It returns error: Missing crypto...
0
by: caldera | last post by:
hi, I want to forms authentication with windows password. So that I import advapi32.dll. Import code like this public static extern bool LogonUser(String lpszUsername,String lpszDomain,String...
2
by: Podi | last post by:
I have ctypes version 0.9.6 and Python 2.4.2 running on Windows XP Professional. When I tried to use some functions in the Advapi32.dll, some functions are available and some are not. Is this a...
1
by: raam_kimi | last post by:
Hi All I got some problem in importing advapi32.dll when i call the LogonUser method it throws an error like this 'Unable to find an entry point named LogonUser in DLL advapi32.dll.' ...
0
by: atmajdesai | last post by:
Hi I am getting this error when i am tring to user RegQueryValueExLong function from advapi32.dll. I imported the dll So please help me out
0
by: Silke Anita Mühlemann | last post by:
Hi there, I'm trying to encrypt Files with EFS, by using functions of the advapi32 dll. But I have problems with the function 'AddUsersToEncryptFile'. I have the name of the file which I want...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.