【问题标题】:.net SSL pfx -> The specified network password is not correct.net SSL pfx -> 指定的网络密码不正确
【发布时间】:2016-06-12 09:14:11
【问题描述】:

我正在构建一个网站,该网站连接到需要 SSL 证书的服务器上的 MySql 数据库。下面的 Ping 方法在我的本地电脑上运行时运行流畅,但是当我将其部署到我们的 Windows 2008 R2 服务器时,出现以下错误: 指定的网络密码不正确。

我尝试使用完全相同的代码创建一个 Windows 窗体应用程序,并且在本地和 Windows 2008 R2 服务器上都能完美运行。

为什么代码在共享服务器上的网站上不起作用?

我看到其他人也有同样的问题,建议使用:

new X509Certificate2(Path, "", X509KeyStorageFlags.MachineKeySet);

但它没有帮助。可能是我用错了!?!

private bool Ping()
{
    string connectionString = "Server=xxx.xxx.xxx.xxx;Port=3306;Database=dbname;
            Uid=server1_ssluser;Pwd=xxxxxxxx;SSL Mode=Required;
            CertificateFile=c:\inetpub\xxxxx\App_Data\Certificates\server1\server1.pfx;"

    try
    {
        using (MySqlConnection connection = new MySqlConnection(connectionString()))
        {
            connection.Open();

            return true;
        }
    }
    catch (Exception ex)
    {
        return false;
    }
}

堆栈跟踪:

System.Security.Cryptography.CryptographicException: The specified network password is not correct. 
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) 
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) 
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String fileName, Object password, X509KeyStorageFlags keyStorageFlags) 
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(String fileName, String password) 
at MySql.Data.MySqlClient.NativeDriver.GetClientCertificates() 
at MySql.Data.MySqlClient.NativeDriver.StartSSL() 
at MySql.Data.MySqlClient.NativeDriver.Open() 
at MySql.Data.MySqlClient.Driver.Open() 
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) 
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() 
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() 
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() 
at MySql.Data.MySqlClient.MySqlPool.GetConnection() 
at MySql.Data.MySqlClient.MySqlConnection.Open() 
at MvcApplication1.Controllers.ValuesController.Ping()

【问题讨论】:

    标签: .net ssl x509certificate2 pfx


    【解决方案1】:

    这可能不是真正的问题,但看起来你没有正确地转义你的字符串。这一行:

    string connectionString = "Server=xxx.xxx.xxx.xxx;Port=3306;Database=dbname;
            Uid=server1_ssluser;Pwd=xxxxxxxx;SSL Mode=Required;
            CertificateFile=c:\inetpub\xxxxx\App_Data\Certificates\server1\server1.pfx;"
    

    应该是:

    string connectionString = @"Server=xxx.xxx.xxx.xxx;Port=3306;Database=dbname;
            Uid=server1_ssluser;Pwd=xxxxxxxx;SSL Mode=Required;
            CertificateFile=c:\inetpub\xxxxx\App_Data\Certificates\server1\server1.pfx;"
    

    否则,您将在字符串中获得控制代码,例如 \i\x

    【讨论】:

      猜你喜欢
      • 2022-12-17
      • 1970-01-01
      • 2012-01-07
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 2022-08-03
      • 1970-01-01
      • 2015-09-02
      相关资源
      最近更新 更多