2

当我使用 CertUtil 将证书导入商店时,例如 ,certutil -f -v -user -privatekey -importPFX my mycert.p12然后在 C# 中读取它,我看到它的导出策略是AllowExport | AllowPlaintextExport.

但是,当使用该方法将同一个证书导入到同一个存储X509Store.Add()区再读回时,导出策略只有AllowExport;我X509KeyStorageFlags.Exportable在将证书导入商店时使用该标志,例如:

...
X509Certificate2Collection x509cert2Collection = new X509Certificate2Collection();
x509cert2Collection.Import(myp12bytes, passwd, X509KeyStorageFlags.Exportable);
foreach (X509Certificate2 x509cert2 in x509cert2Collection) {
    X509Store myStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
    myStore.Add(x509cert2);                          
    myStore.Close();
}
...

我的问题是:有没有办法在 C# 中将 X509Certificate2 添加到 X509Store 中,以便证书的导出策略同时包含AllowExportAllowPlaintextExport?X509KeyStorageFlags 似乎没有定义AllowPlaintextExport标志;只有CngExportPolicies确实。

仅供参考,我使用 .NET Framework 4.6.1 作为目标。

谢谢。

4

0 回答 0