【发布时间】:2013-04-27 02:54:02
【问题描述】:
如何将上传的文件转换为 X509Certificate2 变量?
我尝试使用以下代码,但它不起作用:
public bool hasPublicKey(FileUpload file)
{
bool check = false;
try
{
X509Certificate2 cert = (X509Certificate2)file.PostedFile.InputStream;
}
catch(Exception)
{
check = false;
}
}
【问题讨论】:
-
你上传的到底是什么?是证书还是其他类型的文件?
-
我已经有另一种方法可以检查文件的扩展名是否对应于证书的扩展名。现在,我想将上传的文件转换为 X509Certificate2 数据类型,以便从中获取公钥。但是,Visual Studio 给了我这个错误消息:错误 1 无法将类型 'System.IO.Stream' 转换为 'System.Security.Cryptography.X509Certificates.X509Certificate2'
标签: c# file-upload encryption certificate digital-certificate