Home All Groups Group Topic Archive Search About
Author
12 Feb 2006 2:30 PM
zabutimaxim
Hello everyone,

I need to convert some code that works with CryptoAPI using
advapi32.dll to C#.NET and to use
System.Security.Cryptography. The question is what is the analog for
CryptImportKey API? In the old code they giving to this CryptImportKey
a private key which is byte array 596 bytes length.

Thanks,
Maxim

Author
12 Feb 2006 3:00 PM
Mitch Gallant
That 596 byte is a MS  PRIVATEKEYBLOB unencrypted blob.
..NET api does not support importing these blob types.
You will need to use PInvoke from .NET 1.1 / 2 to import that
RSA keypair. Some samples showing how to set up capi fn prototypes and structs are here:
  http://www.jensign.com/JavaScience/cryptoutils

Also, you can manually import that unencrypted PRIVATEKEYBLOB (if in a file)
using the .NET tool  sn.exe .. e.g.
   sn -i yourprivatekey.snk  MyContainer
but this only works if the privatekeyblob specifies the key as AT_SIGNATURE.

- Mitch Gallant
   MVP Security

<zabutima***@gmail.com> wrote in message
Show quoteHide quote
news:1139754639.488025.256920@z14g2000cwz.googlegroups.com...
> Hello everyone,
>
> I need to convert some code that works with CryptoAPI using
> advapi32.dll to C#.NET and to use
> System.Security.Cryptography. The question is what is the analog for
> CryptImportKey API? In the old code they giving to this CryptImportKey
> a private key which is byte array 596 bytes length.
>
> Thanks,
> Maxim
>
Author
13 Feb 2006 1:42 PM
zabutimaxim
Mitch,

Thanks for answer. Actually we already using it with PInvoke from .NET,
but unfortunatly,
we experiencing probelms with that way, because it looks like CryptoAPI
is not fully thread safe.
Under load more then ~30 concurrent threads it starts to return garbage
in decrypted string.
So we thought to try to use System.Security.Cryptography. We tried to
use PInvoke and synchronize threads, but it also did not help, it looks
like CAPI is not just advapi32.dll, but behind it  there is some
extenral process that advapi32.dll just talking with it  (like RPC). So
it does not help if I synchronize my own threads.
And we also found that there are few people that has same problems with
CAPI.
Any advise?

Regards,
Maxim.