也许我只是遗漏了一些非常基本的东西,或者真的不知道如何解决我当前的问题(有效的选择,我以前只是为了处理证书)。
我需要打开一个在C#中使用X509证书的ODBC连接。但无论我尝试什么,我都会被问到是否相信证书。似乎我不知道如何构建这个连接字符串。
我知道我可能必须在我正在运行我的应用程序的机器上安装证书(我已经这样做了,并且它仍然有效100年)。
我为此搜索了很多,我只是不明白。我找到的只是如何从DB-Server端强制执行证书验证。这不是我需要的,我想和DB谈谈 - 我是客户。
到目前为止,我在X09Store中拥有Cert并且可以从那里检索它而没有任何问题,但是如何使用它在ODBC-Connection中信任/验证证书?
这是我到目前为止所做的:
X509Store = new X509Store("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
//This is the X509Certificate2-Object
var cert = GetCertificate(store);
//Best would be if I can add the cert somehow in the connection string?
var conString = "DSN=MYDSN; TrustServerCertificate=yes; Encrypt=yes";
OdbcConnection con = new OdbcConnection();
try
{
//This where the annoying pop up appears and asks if I trust the cert
con.Open();
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
con.Close();
}
storeClose();
如果有人可以给我一个指针或者告诉我如何构建corect ConnectionString,我真的很感激。
干杯