Esempio n. 1
0
 public static extern bool CryptUIWizExport
 (
     [param: In, MarshalAs(UnmanagedType.U4)] CryptUIWizExportFlags dwFlags,
     [param: In, MarshalAs(UnmanagedType.SysInt)] IntPtr hwndParent,
     [param: In, MarshalAs(UnmanagedType.LPWStr)] string pwszWizardTitle,
     [param: In] ref CRYPTUI_WIZ_EXPORT_INFO pExportInfo,
     [param: In, MarshalAs(UnmanagedType.SysInt)] IntPtr pvoid
 );
 private void exportPrivateKey_Click(object sender, EventArgs e)
 {
     var root = _certificateProvider.GetRootCertificate();
     var exportInfo = new CRYPTUI_WIZ_EXPORT_INFO();
     exportInfo.context = new CRYPTUI_WIZ_EXPORT_INFO_UNION { pCertContext = root.Handle };
     exportInfo.cStores = 0;
     exportInfo.dwSize = (uint)Marshal.SizeOf(typeof(CRYPTUI_WIZ_EXPORT_INFO));
     exportInfo.dwSubjectType = CryptUIExportInfoSubjectType.CRYPTUI_WIZ_EXPORT_CERT_CONTEXT;
     exportInfo.pwszExportFileName = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "FiddlerRootCert.pfx");
     exportInfo.rghStores = IntPtr.Zero;
     NativeMethods.CryptUIWizExport(CryptUIWizExportFlags.CRYPTUI_WIZ_EXPORT_PRIVATE_KEY | CryptUIWizExportFlags.CRYPTUI_WIZ_EXPORT_NO_DELETE_PRIVATE_KEY, Handle, "Export Fiddler Root Certificate", ref exportInfo, IntPtr.Zero);
 }