Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否使用AllowPlaintextExport标志将C#X509Certificate2添加到X509Store?_C#_.net_X509certificate_X509certificate2_Cng - Fatal编程技术网

是否使用AllowPlaintextExport标志将C#X509Certificate2添加到X509Store?

是否使用AllowPlaintextExport标志将C#X509Certificate2添加到X509Store?,c#,.net,x509certificate,x509certificate2,cng,C#,.net,X509certificate,X509certificate2,Cng,当我使用CertUtil将证书导入到存储中时,例如,CertUtil-f-v-user-privatekey-importPFX my mycert.p12,然后在C中读取它,我看到它的导出策略是AllowExport | AllowPlaintextExport 但是,当使用X509Store.Add()方法将同一证书导入同一存储,然后将其读回时,导出策略仅为AllowExport;将证书导入存储时,我使用x509keystrageflags.Exportable标志,例如: ... X509

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

但是,当使用
X509Store.Add()
方法将同一证书导入同一存储,然后将其读回时,导出策略仅为
AllowExport
;将证书导入存储时,我使用
x509keystrageflags.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();
}
...
我的问题是:是否有办法将X509Certificate2添加到C#中的X509Store中,以使证书的导出策略同时包括
AllowExport
AllowPlaintextExport
?X509keystrageFlags似乎没有定义
AllowPlaintextExport
标志;只有
CngExportPolicies
可以

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


谢谢。

是否有使用此标志的商业案例?我正在导出cng键以创建所述的BouncyCastle键,例如。当使用certutil导入的证书执行此操作时,它会工作,但使用添加了C#API的证书执行此操作时会引发异常。