RE: Using der encoded Public Key from certificate with CryptEncryp



Köszönöm a segítséget :)
Thank you for the help, it was vey useful!

"lelteto" wrote:

I am afraid you would need to PARSE the cert yourself to get the public key
value. Althogh there are surely ASN.1 parsers avilable, considering that your
code is on mobile platform, you probably don't want to add a full parser
code's overhead. So the best for you would be to write a minimal ASN.1 parser
which looks only for the public key part (and skip everything else).

One important note (for RSA public keys):
When you get the public key value, it would be in big endian (=network byte
order) - both the modulus and the public exponent (although the latter will
most probably be 65537 = 0x010001 which is the same both endianness). You
will need to REVERSE the byte order when you build your PUBLICKEY blob for
the MS CAPI which expects it to be in little endian (Intel x86) byte order.
And the public exponent will be DWORD.

Laszlo Elteto
SafeNet, Inc.

"Balint F. Zoltan" wrote:

Thanks for the fast reply, but the problem is that I can use only
CryptEncrypt because the application is written for windows mobile and there
is no CryptEncryptMessage. I searched a lot and I didn't find nothing to
solve my problem...

"lelteto" wrote:

Bálint,

Instead of CryptEncrypt, you should use CryptEncryptMessage, which uses the
certificate (context) directly. To get the cert context first you can create
an in-memory temp store with CertOpenStore(CERT_STORE_PROV_MEMORY) then add
the cert to the store with CertAddEncodedCertificateToStore.
Hope this will help you.

Éltető László
SafeNet, Inc.

"Balint F. Zoltan" wrote:

Hello,

I have an X509 Certificate in C# and I extraxt the pulic key from it. I need
this key to encrypt something with RSA and then send it. For the encryption I
need to use
CryptEncrypt but the CryptImportKey needs a key blob. What can I do? Could
somebody help me?

Thanks, Zoltan
.


Quantcast