我想實現的解決方案到我的應用程序,反映了答案in this post「專用密鑰」沒有一個定義,「CreateFromFile」
我有一個類似的場景,我有一個HttpListener
和Grapevine
基於應用程序上運行我需要獲得使用Mono
HTTPS
,我試圖創建幷包括相關按鍵的工作Ubuntu的服務器允許HTTPS
我遇到的問題是該解決方案的最後一行,
key = PrivateKey.CreateFromFile (pvk_file).RSA;
當我嘗試同樣的Visual Studio顯示錯誤/文本高亮紅,'PrivateKey' does not have a definition for 'CreateFromFile'
我使用了錯誤的庫或者是別的東西與我的代碼本身的問題?
我的代碼,減少到相關的方法。
using System;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using java.security;
public class ConfigureCertificates
{
private readonly string _dirName;
private readonly string _path;
private readonly string _port;
private readonly string _certFile;
public ConfigureCertificates(string port)
{
_dirName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
_path = Path.Combine(_dirName, ".mono");
_path = Path.Combine(_path, "httplistener");
_port = port;
_certFile = Path.Combine(_path, String.Format("{0}.cer", _port));
}
public void SetUpCerts()
{
if (!File.Exists(_certFile))
throw new Exception("Certificate file not found");
string pvkFile = Path.Combine(_path, String.Format("{0}.pvk", _port));
if (!File.Exists(pvkFile))
throw new Exception("Private key not found");
var cert = new X509Certificate2(_certFile);
var key = PrivateKey.CreateFromFile(pvkFile).RSA; // Error occurs here
}
}
嘗試使用完整的命名空間,或許這裏有類名的衝突。 'Mono.Security.Authenticode.PrivateKey.CreateFromFile()' – DavidG
這就是現貨。謝謝。只需要添加來自Nuget的'Mono.Security' –