简体   繁体   English

X509Certificate和.NET Compact Framework 3.5

[英]X509Certificate and .NET Compact Framework 3.5

I am trying to implement HTTP communication authenticated by client certificate. 我正在尝试实现通过客户端证书认证的HTTP通信。 When sending an HTTP request on "normal" (ie not Compact) .NET Framework, it's quite simple: 在“普通”(即非紧凑型).NET Framework上发送HTTP请求时,它非常简单:

HttpWebRequest request = ...;
string certificatePath = ...;
string certificatePassword = ...;

request.ClientCertificates.Add(
    new X509Certificate(certificatePath, certificatePassword));                  

However, on Compact Framework 3.5, X509Certificate has only one constructor which accepts byte array and nothing else. 但是,在Compact Framework 3.5上, X509Certificate仅具有一个接受字节数组的构造函数,而别无其他。 I suppose that I should read a certificate file and pass its contents into that byte array, but what about the password? 我想我应该读取一个证书文件并将其内容传递到该字节数组中,但是密码呢? How should I specify it on Compact Framework? 我应该如何在Compact Framework上指定它?

I did not find any way to use X509Certificate and password. 我找不到任何使用X509Certificate和密码的方法。

In the end, I've decided to use X509Store and grab certificates from there. 最后,我决定使用X509Store并从那里获取证书。 This will make deployment a bit more difficult then originally anticipated, but at least it's doable :) 这将使部署比最初预期的要困难一些,但至少是可行的:)

I'm two years late, but I stumbled across this question in my own research. 我迟了两年,但在自己的研究中偶然发现了这个问题。

If you look closely at the documentation's example code, you see that you have to first open the PFX file and then export it before creating another instance of the X509Certificate class. 如果仔细查看文档的示例代码,您会发现必须先打开PFX文件,然后将其导出,然后再创建X509Certificate类的另一个实例。

The way I understood this is as follows: the full .NET Framework API (ie, on the desktop) takes a password parameter for the class' constructor as an overload. 我的理解方式如下:完整的.NET Framework API(即,在桌面上)采用类的构造函数的密码参数作为重载。 So, using the full framework, you export the certificate's raw data (ie, without the securing password) using the Export method and then store the resulting byte array into a file. 因此,使用完整框架,您可以使用Export方法导出证书的原始数据(即,没有安全密码),然后将结果字节数组存储到文件中。 Afterward, you transfer that file to the mobile device, read the file into a byte array and pass that to the X509Certificate constructor on the Compact Framework. 之后,您将该文件传输到移动设备,将该文件读入字节数组,然后将其传递到Compact Framework上的X509Certificate构造函数。

Of course, this is the "raw" way of going about the problem. 当然,这是解决问题的“原始”方法。 One has to then take care to secure the data being transferred in some way. 然后必须注意以某种方式保护正在传输的数据。

On further reading, exporting the PFX file in this way does not include the private key, though. 在进一步阅读时,以这种方式导出PFX文件不包括私钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM