VoimiX
VoimiX

Reputation: 1190

How to work with CryptoAPI via C#?

There is a group of CryptoApi functions which works with crypto service providers (CSP).

CPAcquireContext
CPCreateHash
CPDecrypt
CPDeriveKey
CPDestroyHash
CPDestroyKey
CPDuplicateHash
CPDuplicateKey
CPEncrypt
CPExportKey
CPGenKey
CPGenRandom
CPGetHashParam
CPGetKeyParam
CPGetProvParam
CPGetUserKey
CPHashData
CPHashSessionKey
CPImportKey
CPReleaseContext
CPSetHashParam
CPSetKeyParam
CPSetProvParam
CPSignHash
CPVerifySignature

Yes, I know that there is System.Cryptography namespace. But I don't need their implementations.

Is there any ready library which provides a .NET wrapper to these functions?

Upvotes: 4

Views: 13557

Answers (2)

The Moof
The Moof

Reputation: 804

I think your best bet is to use P/Invoke to pull the functionality into your C# application. Here's an (old) article on MSDN about using P/Invoke and CryptoAPI in C#:

Extending .NET Cryptography with CAPICOM and P/Invoke

It's for .Net 1.1, but the concepts are still the same.

Upvotes: 1

sehe
sehe

Reputation: 392833

There has been an extended article on MSDN about this topic:

Extending .NET Cryptography with CAPICOM and P/Invoke

An article on using CryptoAPI Certificate Stores from .Net.

Some P/Invoke declarations lifted from this blog post that shows the p/Invoke definitions for it:

[snip] code sample too large for SO [/snip]

Upvotes: 3

Related Questions