How to Install Personal Security Certificate in C# compact framework using PFXIsPFXBlob(), CertAddCertificateContextToStore() functions ~ Siccolo - Free Management Tool For SQL Server!

Friday, February 1, 2008

How to Install Personal Security Certificate in C# compact framework using PFXIsPFXBlob(), CertAddCertificateContextToStore() functions

Access web service with required personal security certificate - using x509 PFX personal certificate - Install Personal Security Certificate in C# compact framework. :




Top Blogs


Software





...
byte[] pfxData = GetFile(certificatePath);
...
CRYPT_DATA_BLOB pPFX = new CRYPT_DATA_BLOB();
pPFX.cbData = pfxData.Length;
pPFX.pbData = Marshal.AllocHGlobal(pfxData.Length);
Marshal.Copy(pfxData, 0, pPFX.pbData, pfxData.Length);
...
hMemStore = PFXImportCertStore(ref pPFX, password, CRYPT_USER_KEYSET);
...
cert_MY_store = CryptoAPI.CertOpenStore(new IntPtr(CERT_STORE_PROV_SYSTEM_W),
0,
IntPtr.Zero,
CERT_SYSTEM_STORE_CURRENT_USER,
"MY");

...
...
CertAddCertificateContextToStore(cert_MY_store,
hCertCntxt,
(int)CERT_STORE_ADD_REPLACE_EXISTING, IntPtr.Zero)




1 comment:

Alberto Silva said...

Hi,
I've been trying your code in Windows Mobile 5 and 6 devices and emulators, and it always fails on the same place, with the exact same error:
errorInfo = "Failed to open personal store:\nWin32Exception"
The particular error is 122.

Do you have any idea of what may be causing it?