Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.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
C# 在Windows应用商店XAML应用程序中安装客户端证书_C#_Xaml_Windows 8_Winrt Xaml - Fatal编程技术网

C# 在Windows应用商店XAML应用程序中安装客户端证书

C# 在Windows应用商店XAML应用程序中安装客户端证书,c#,xaml,windows-8,winrt-xaml,C#,Xaml,Windows 8,Winrt Xaml,我想在Windows应用商店XAML应用程序中使用客户端证书身份验证。我使用makecert创建了自签名CA和客户端证书,身份验证在IIS/ASP.NET+浏览器(IE10、Chrome等)中运行良好。 现在我想在Windows应用商店应用程序中使用它,但不确定如何实际安装证书。我有一个cert.pfx文件,我导入到IE10。 下面是我用来通过SSL使用HTTP服务的代码 HttpClientHandler handler = new HttpClientHandler(); handler.C

我想在Windows应用商店XAML应用程序中使用客户端证书身份验证。我使用makecert创建了自签名CA和客户端证书,身份验证在IIS/ASP.NET+浏览器(IE10、Chrome等)中运行良好。 现在我想在Windows应用商店应用程序中使用它,但不确定如何实际安装证书。我有一个cert.pfx文件,我导入到IE10。 下面是我用来通过SSL使用HTTP服务的代码

HttpClientHandler handler = new HttpClientHandler();
handler.ClientCertificateOptions = ClientCertificateOption.Automatic;

HttpClient client = new HttpClient(handler);
不确定ClientCertificateOption.Automatic和ClientCertificateOption.Manual之间有什么区别。 当我尝试连接时,证书未显示在服务器上,并且出现401错误,我猜测证书未显示在app cert store中,因此未向服务器发送任何内容。那么我如何安装证书呢

我应该使用CertificateRollmentManager.ImportPfxDataAsync()方法吗?如果是,如何将.pfx转换为“Base64编码的pfx消息” pfx应该包含私钥吗


或者我应该使用此处描述的证书扩展名:

以下代码将加载一个pfx文件并创建一个base64编码的字符串,该字符串可由ImportPfxDataAsync方法使用:

StorageFolder packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder certificateFolder = await packageLocation.GetFolderAsync("Certificates");
StorageFile certificate = await certificateFolder.GetFileAsync("YourCert.pfx");

IBuffer buffer = await Windows.Storage.FileIO.ReadBufferAsync(certificate);
string encodedString = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffer);
这假定您将证书放在“证书”文件夹中

您可能希望了解在windows 8应用程序中使用客户端证书与asp.net web api通信的端到端场景