Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Questions About CryptoAPI

279 views
Skip to first unread message

Carmen

unread,
Jan 8, 2007, 5:43:15 PM1/8/07
to
Hi Folks,
I am searching for an encryption/decryption wrapper in Delphi for the
Windows CryptoAPI. I found something called Wcrypt2 (.pas & .dcu) and also
downloaded a sample project. But the program failed right after calling
CryptAcquireContext.

Is there something that I need to install or set up on my computer
before using the CryptoAPI functions in Delphi (5)?

Or do I need a higher version of Delphi to make it work?

Thanks very much in advance,

Carmen


danny heijl

unread,
Jan 9, 2007, 11:26:33 AM1/9/07
to
Carmen schreef:

> But the program failed right after calling
> CryptAcquireContext.

This doesn't give us any useful information.

If CryptAcquireContext fails, you are supposed to call GetLastError to
retrieve the error code, this might give you (and us) an indication why
it fails.

> Is there something that I need to install or set up on my computer
> before using the CryptoAPI functions in Delphi (5)?

Not really, unless your OS predates Win98.

> Or do I need a higher version of Delphi to make it work?

No, D5 is fine.

Danny
---

John Herbster

unread,
Jan 9, 2007, 1:25:56 PM1/9/07
to

> The error code returned after CryptAcquireContext is:
2148073494. It seems like a really strange error code.

Danny,
In hexadecimal it is 0x80090016 -- is this less strange?
You may want to review
http://www.google.com/search?q=0x80090016+CryptAcquireContext
HTH, JohnH


Carmen

unread,
Jan 9, 2007, 1:16:03 PM1/9/07
to
Hi Danny,

Thanks for the reply.

The error code returned after CryptAcquireContext is: 2148073494. It seems
like a really strange error code.

Here is the code:

procedure TmainForm.initAPI(Key: String);
var errCode: DWORD;
begin
hProv:=0;
hKey:=0;
hHash:=0;

if NOT CryptAcquireContext(@hProv, nil, nil, PROV_RSA_FULL, 0) then
begin
errCode:= GetLastError;
showMessage('CryptoAPI error during: CryptAcquireContext '+
IntToStr(errCode));
end;
...
end; // initAPI

Regards,

Carmen


"danny heijl" <danny_dot_heijl_at_cevi_dot_be> wrote in message
news:45a3c1fd$1...@newsgroups.borland.com...

danny heijl

unread,
Jan 9, 2007, 2:11:07 PM1/9/07
to
Carmen schreef:

> The error code returned after CryptAcquireContext is: 2148073494. It seems
> like a really strange error code.

The error code (NTE_BAD_KEYSET) tells you that you don't have 'default'
container in the CSP. If you don't need one you should use the
CRYPT_VERIFYCONTEXT flag in CryptAcquireContext.

Danny
---

Carmen

unread,
Jan 9, 2007, 5:05:06 PM1/9/07
to
Thanks guys,
It worked after I put in the flag!

One more question, I have a Visual Studio .NET program which uses the
DESCryptoServiceProvider class to encrypt/decrypt files (which requires a
key and an initialization vector). Does the CryptoAPI have anything that is
equivalent to this? Basically I want to be able to decrypt a file with the
same key in both the Delphi and .NET programs.

Thanks very much!

Carmen

"danny heijl" <danny_dot_heijl_at_telenet_dot_be> wrote in message
news:45a3...@newsgroups.borland.com...

danny heijl

unread,
Jan 10, 2007, 3:09:07 AM1/10/07
to
Carmen schreef:

> I have a Visual Studio .NET program which uses the
> DESCryptoServiceProvider class to encrypt/decrypt files (which requires a
> key and an initialization vector). Does the CryptoAPI have anything that is
> equivalent to this?

Yes, as the .Net crypto classes mostly use the CryptoApi internally (but
in some cases extend it substantially). CryptEncrypt encrypts, and when
creating the session key with CryptDeriveKey you specify the encryption
algorithm to be used.

Danny
---

Carmen

unread,
Jan 10, 2007, 12:57:34 PM1/10/07
to
Thanks Danny,
The .NET classes such as DESCryptoServiceProvider all require an
initialization vector besides a key. The Crypto API CryptEncrypt only
requires a key generated from CryptDeriveKey with a password. So how does a
key and an IV in .NET equate to a single password or key in CryptEncrypt?
This is what confuses me.

Thanks again,

Carmen

"danny heijl" <danny_dot_heijl_at_cevi_dot_be> wrote in message

news:45a49ee6$1...@newsgroups.borland.com...

danny heijl

unread,
Jan 10, 2007, 2:50:59 PM1/10/07
to
Carmen schreef:

> So how does a
> key and an IV in .NET equate to a single password or key in CryptEncrypt?

You use CryptSetKeyParam once you have the handle to the key.

Danny
---

danny heijl

unread,
Jan 10, 2007, 2:53:08 PM1/10/07
to
Carmen schreef:

> This is what confuses me.

Then perhaps you should read this first:

http://www.jensign.com/JavaScience/dotnet/NetDESEncrypt/index.html

Danny
---

0 new messages