4
我需要此帮助:程序化在Windows 8中使用SSL证书应用程序
我们的后端通过自签名证书进行保护。让我们称之为:OurMegaCoolCertificate.cer
因此,我们通过使用certmgr.msc将此证书导入到我们的开发人员机器。现在,我们可以使用下面的代码检索我们的后端数据:
async public static Task<string> getData(string Id, string Type)
{
String url = "https://BACKEND/API/?Id=" + Id + "&Type=" + Type;
HttpClientHandler aHandler = new HttpClientHandler();
aHandler.ClientCertificateOptions = ClientCertificateOption.Automatic;
HttpClient aClient = new HttpClient(aHandler);
aClient.DefaultRequestHeaders.ExpectContinue = false;
aClient.DefaultRequestHeaders.MaxForwards = 3;
Uri requestUri = new Uri(url);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, requestUri);
//request.Headers.ExpectContinue = false;
var result = await aClient.GetAsync(requestUri, HttpCompletionOption.ResponseContentRead);
var responseHeader = result.Headers;
//Debug.WriteLine(responseHeader.WwwAuthenticate);
var responseBody = await result.Content.ReadAsStringAsync();
return responseBody;
}
但offcourse我们不能告诉我们的应用程序的用户,手动安装该证书,有没有办法来添加该证书项目和用它?或编程导入到用户机器?请指导我,我是新来的SSL安全
我已经成功地做到这一点,没有错误,但请求失败,貌似请求没有找到证书:
private async void GetOverHere()
{
//await Windows.Security.Cryptography.Certificates.CertificateEnrollmentManager.InstallCertificateAsync("",InstallOptions.None);
StorageFolder packageLocation = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder certificateFolder = await packageLocation.GetFolderAsync("Certificates");
StorageFile certificate = await certificateFolder.GetFileAsync("OurMegaCoolCertificate.cer");
IBuffer buffer = await Windows.Storage.FileIO.ReadBufferAsync(certificate);
string encodedString = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(buffer);
await Windows.Security.Cryptography.Certificates.CertificateEnrollmentManager.InstallCertificateAsync(encodedString, InstallOptions.None);
}
此外,我们已经尝试再次
</Capabilities>
<Extensions>
<!--Certificates Extension-->
<Extension Category="windows.certificates">
<Certificates>
<Certificate StoreName="Root" Content="Assets\OurMegaCoolCertificate.cer" />
</Certificates>
</Extension>
而且,当我们导入使用certmgr.msc到受信任的根证书 - 所有作品
:做这个清单中
也许这会帮助你,https://stackoverflow.com/questions/12337721/how-to-programmatically-install-a-certificate-using-c-尖锐和https://stackoverflow.com/questions/566570/how-can-i-install-a-certificate-into-the-local-machine-store-programmatically-us – vzamanillo
您的链接仅适用于Windows 8.1 – Cheese
我尝试过,但我得到的响应代码404。哪里将使用GetOverHere()方法? – ranjith