Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
certaddencodedcertificatetostore (crypt32)
 
.
Summary
Creates a certificate context from an encoded certificate and adds it to the certificate store.

C# Signature:

[DllImport("CRYPT32.DLL", EntryPoint = "CertAddEncodedCertificateToStore", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool CertAddEncodedCertificateToStore(IntPtr certStore, int certEncodingType, byte[] certEncoded, int certEncodedLength, int addDisposition, IntPtr certContext);

VB Signature:

Declare Function CertAddEncodedCertificateToStore Lib "crypt32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

IntPtr store = CertOpenSystemStore(0, CERT_STORE_NAME);

if(store != IntPtr.Zero) {
    FileStream ifs = new FileStream("MyTest.cer", FileMode.Open, FileAccess.Read);
    if(ifs != null) {
        byte[] cert = new byte[ifs.Length];

        for(int i = 0; i < ifs.Length; i++){
            cert[i] = (byte)ifs.ReadByte();
        }

        if(CertAddEncodedCertificateToStore(store, X509_ASN_ENCODING, cert, cert.Length, CERT_STORE_ADD_REPLACE_EXISTING, IntPtr.Zero)) {
            MessageBox.Show("Certificate added");
        } else {
            MessageBox.Show("Could not add certificate");
        }
    } else {
            MessageBox.Show("Could not open certificate file");
    }

    CertCloseStore(store, 0);
}

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions