如何将上传的文件转换为X509Certificate2变量?
我尝试使用以下代码,但它不起作用:
public bool hasPublicKey(FileUpload file)
{
bool check = false;
try
{
X509Certificate2 cert = (X509Certificate2)file.PostedFile.InputStream;
}
catch(Exception)
{
check = false;
}
}发布于 2013-05-03 03:53:16
如果上传的文件是一个有效的证书,那么您应该查看X509Certificate2类中的constructor或Import方法。
你会发现你需要这样的东西:
var fileLength = file.PostedFile.ContentLength;
var certdata = new byte[fileLength];
file.FileContent.Read(certData, 0, fileLength);
var cert = new X509Certificate2(certData);(代码未经验证,但它,或者非常类似的东西,应该可以工作)。
发布于 2013-05-03 04:07:28
public bool hasPublicKey(FileUpload file)
{
bool check = false;
try
{
X509Certificate2 cert = new X509Certificate2(file.FileBytes);
if (cert.PublicKey != null)
{
check = true;
}
}
catch(Exception)
{
check = false;
}
return check;
}https://stackoverflow.com/questions/16346438
复制相似问题