Following is the C code to import a certificate into the Windows trusted root certificate store using CryptoAPI:
PCCERT_CONTEXT pCertCtx = NULL;
if (CryptQueryObject (
CERT_QUERY_OBJECT_FILE,
L”D:\\selva\\b64.cer”,
CERT_QUERY_CONTENT_FLAG_ALL,
CERT_QUERY_FORMAT_FLAG_ALL,
0,
NULL,
NULL,
NULL,
NULL,
NULL,
(const void **)&pCertCtx) != 0)
{
HCERTSTORE hCertStore = CertOpenStore (
CERT_STORE_PROV_SYSTEM,
0,
0,
CERT_STORE_OPEN_EXISTING_FLAG |
CERT_SYSTEM_STORE_LOCAL_MACHINE,
L”ROOT”);
if (hCertStore != NULL)
{
if (CertAddCertificateContextToStore (
hCertStore,
pCertCtx,
CERT_STORE_ADD_ALWAYS,
NULL))
{
cout << “Added certificate to store.” << endl;
}
if (CertCloseStore (hCertStore, 0))
{
cout << “Cert. store handle closed.” << endl;
}
}
if (pCertCtx)
{
CertFreeCertificateContext [...]
Entries Tagged as ‘Coding is fun’
June 9, 2008
CryptoAPI: How to import a certificate
March 14, 2008
Boxing/Unboxing in .NET
This post has been long overdue; I should have posted it two months back. Anyway, a couple of my friends attended training in .NET concepts sponsored by my company. They came back from the training and discussed with me the stuff they had learnt. One of the fellows mentioned that they had been taught that [...]
December 10, 2007
Some more COM+ configuration issues
As the release date of our project was nearing, I had become a bit busier in the past few weeks. That would explain the absence of any activity in this blog. The long coding and debugging sessions were fun. We faced plenty of issues during deployment in our test environment. Had loads of fun solving [...]
June 13, 2007
Weird problem with shdocvw.dll
I had added a reference to shdocvw.dll in my project. Everything was working fine till day before yesterday. After I left office on Monday night, shdocvw.dll got unregistered somehow. So, when I returned back to work on Tuesday morning, I found that all applications referencing shdocvw.dll were broken and wouldn’t compile. The applications kept popping [...]
May 25, 2007
Brainf*ck
++++++++++
[>+++>+++++++>++++++++++>+++++++++++>++++++++++++<<<<<-]
>>+++.<++.
>>>–.<+.—-.>++++++.—-.++++++.<<<.
>>+.>–.<-.++++++++.>—-.<—.>+++++++.<—.++++++++.<<.
>>>-.—–.<——-.—.>>+.<<<<.
>>.>-.<+++.<<.
>.<.
>>>–.+++.+++++++.<+.-.<<.
>>+++++.>–.<<<++++++++++++++.
If you do not understand what I have written above, check out this link first: http://en.wikipedia.org/wiki/Brainfuck
April 13, 2007
I’m becoming GOOD
During college days, I had always dreaded the concepts of “multithreading” and “race conditions”. I never grasped these ideas back then. I had been doing some reading on these topics lately and discovered that it is not rocket science, after all. I was even able to implement a mutithreading model in my current project. My [...]
March 5, 2007
A subtle bug
In a recent programming assignment, I wrote code which looked something like this:
if (condition1)
if (condition2)
doSomething ();
else
if (condition3)
doSomethingElse ();
On running the code, I realized that the ‘else’ clause wasn’t being executed when ‘condition1′ failed. On debugging, I found that the ‘else’ clause was executed when ‘condition2′ failed. That was when I remembered the programming wisdom I [...]
February 6, 2007
Memory leaks?? In Java and .NET??!
Till a few weeks ago, I was one of those guys who are under the impression that memory leaks could NEVER occur in Java and .NET as the garbage collection is taken care of by the runtime environment for the programmer. If you are like me, let me tell you the plain, simple truth that: [...]