Code:
public class Certificationhelper {public static bool Importpfx (string Certpath, String certpass) { Create a Collection object and populate it using the PFX file x509certificate2collection collection = New X509Certificate2Collection (); try {collection. Import (Certpath, Certpass, X509keystorageflags.persistkeyset); foreach (X509Certificate2 cert in collection) {X509store store = new X509store (); Store. Open (openflags.maxallowed); Store. ADD (CERT); Store. Close (); Import the certificate into an X509store object}} catch (Exception e) {//throw (e); return false; } return true; public static bool Importcer (string cerfilename) {try { X509Certificate2 certificate = new X509Certificate2 (cerfilename); X509store store = new X509store (Storename.trustedpublisher, storelocation.localmachine); Store. Open (Openflags.readwrite); Store. ADD (certificate); Store. Close (); } catch {return false; } return true; } }
The specific namespace has been forgotten, you can find it yourself.
C # tool class for importing PFX and CER certificates