How to Encrypt and Decrypt with CryptoAPI and a user Certificate (Windows Mobile)


Hi all, welcome back,

The other day I had the pleasure to collaborate with my colleague Raffaele Limosani on a CryptoAPI case in Windows Mobile. I don't give technical support to Windows Mobile, and I don't know the specifics on mobile development. He does 😉 So we managed to put together a sample which shows how to encrypt and decrypt data with a certificate in a PFX file and works on that platform: Encrypting\Decrypting Data through PFX certificate on Windows Mobile.

CryptoAPI is limited on Windows Mobile. Some methods are not supported, and we may find differences in the supported methods: number of parameters, flags... We could use the ideas shown in this sample if we want to do the same stuff on Windows NT (XP, Vista, Server 2008, etc.). Just pay attention to the differences I mentioned. MSDN will be our friend here, as always.

The sample shows the usage of the following CryptoAPI methods on encryption:

- CertOpenStore.

- CertFindCertificateInStore

- CryptAcquireContext

- CryptImportPublicKeyInfoEx

- CryptEncrypt

- CertFreeCertificateContext

- CertCloseStore

And on decryption:

- CertOpenStore

- CertFindCertificateInStore

- CryptAcquireCertificatePrivateKey

- CryptGetUserKey

- CryptDecrypt

- CertFreeCertificateContext

- CertCloseStore

 

I hope this helps.

Cheers,

 

Alex (Alejandro Campos Magencio)

Skip to main content