2
我試圖用X509Certificate2.CreateFromCertFile()
方法在ASP.NET應用程序的核心,但它好像它不支持.NET的核心。X509Certificate2.CreateFromCertFile().NET的核心
有來自CERT/PFX文件創建一個X509Certificate2
對象的另一種方式?
我試圖用X509Certificate2.CreateFromCertFile()
方法在ASP.NET應用程序的核心,但它好像它不支持.NET的核心。X509Certificate2.CreateFromCertFile().NET的核心
有來自CERT/PFX文件創建一個X509Certificate2
對象的另一種方式?
也許這樣的事情?
public Certificate CreateFromCertFile()
{
string cerFile = @"c:\cer.txt";
string keyFile = @"c:\key.txt";
var cert = new X509Certificate2(cerFile);
cert.PrivateKey = CreateRSAFromFile(keyFile);
return cert;
}
private RSACryptoServiceProvider CreateRSAFromFile(string filename)
{
byte[] pvk = null;
using (var fs = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
{
pvk = new byte[fs.Length];
fs.Read(pvk, 0, pvk.Length);
}
var rsa = new RSACryptoServiceProvider();
rsa.ImportCspBlob(pvk);
return rsa;
}