store ssl root certificate programmatically

J

jwei

i tried to add a root certificate via code :

....//read cert file into buffer
X509Certificate cert = new X509Certificate(buffer); //cert is ok
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadWrite);
store.Certificates.Add(cert);
store.Close();

but the certificate doesnt get added

so i tried it with native function :
CertOpenStore/CertAddEncodedCertificateToStore

with this functions i can add the certifiacte to HKCU -> Ca or trust without
prompt (i cannot add to Root, since i dont have a display)

but if a do a WebRequest to a ssl url, it doesnt work (cannot establish a
trust connection ...)

if a add my certificate during os desing phase to the sysroots.p7b the
request works fine - but i want to add the certificate during runtime ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top