PDO和openssl_public_decrypt失败 [英] PDO and openssl_public_decrypt failing

查看:295
本文介绍了PDO和openssl_public_decrypt失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将密码解密并更新到mysql数据库表中.而这样做却给了我一个奇怪的错误.

I am trying to decrypt and update password into a mysql database table. while doing it is giving me a weird error.

PHP警告:PDO :: exec():SSL操作失败,代码为1.OpenSSL 错误消息:错误:0906D06C:PEM例程:PEM_read_bio:无起始行 在 .../供应商/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php 在306行上的PHP警告:PDO :: exec():MySQL服务器已经消失了 .../供应商/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php 在306行上的PHP警告:PDO :: exec():读取结果集的错误 标头中 ../vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php 在306行

PHP Warning: PDO::exec(): SSL operation failed with code 1. OpenSSL Error messages: error:0906D06C:PEM routines:PEM_read_bio:no start line in .../vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 306 PHP Warning: PDO::exec(): MySQL server has gone away in .../vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 306 PHP Warning: PDO::exec(): Error reading result set's header in ../vendor/robmorgan/phinx/src/Phinx/Db/Adapter/PdoAdapter.php on line 306

  • 密码使用私钥加密.
    • openssl_private_encrypt函数用于加密.
      • passwords are encrypted using private key.
        • openssl_private_encrypt function is used for encryption.
        • 用于加密解密的代码:

           function processPlainText($plainText, $action) {
                  $cryptText = '';
                  $res = 'encrypt' == $action ? openssl_get_privatekey($this->keyContents) : openssl_get_publickey($this->keyContents);
                  $action = 'encrypt' == $action ? 'openssl_private_' . $action : 'openssl_public_'.$action;
          
                  $action($plainText, $cryptText, $res);
                  openssl_free_key($res);
                  return $cryptText;
              }
          

          任何对此问题的见解将不胜感激.

          Any insight on this problem would be much appreciated.

          有效的代码:

          $pdo = getMysqlPdoInstance(); //get pdo instance using ssl
          $id = 101;
          $plainText = 'abcd';
          $password = processPlainText($plainText, 'encrypt');
          $count = $pdo->exec(sprintf("UPDATE table set password =  '%s' WHERE id = %d", $password, $id));
          print("Updated $count rows.\n");
          

          失败的代码:

          $pdo = getMysqlPdoInstance(); //get pdo instance using ssl
          $id = 101;
          $password = processPlainText($encryptedPassword, 'decrypt');
          $count = $pdo->exec(sprintf("UPDATE table set password =  '%s' WHERE id = %d", $password, $id));
          print("Updated $count rows.\n");
          

          谢谢

          推荐答案

          在Mysql连接中使用SSL会使您遇到错误,已通过补丁("openssl_decrypt触发PDO中的错误")到PHP 7.1,尚无反向端口.在撰写本文时,在最后的评论中,可以找到解决方法的说明:

          Using SSL for the Mysql connection made you hit a bug, resolved with a patch ("openssl_decrypt triggers bug in PDO") to PHP 7.1, with no backports yet. In the last comment at the time of writing, instructions to a workaround can be found:

          ..请在您的应用程序/脚本中的openssl_pkey_get_public之后调用openssl_error_string().

          .. please call openssl_error_string() after openssl_pkey_get_public in your app / script.

          在函数中,如果不能移动到PHP7.1,则将while(openssl_error_string() !== false);放在openssl_free_key()上方.

          in your function, place while(openssl_error_string() !== false); above openssl_free_key() if you cannot move to PHP7.1.

          在您适当怀疑的评论中,当使用openssl_public_decrypt时,PDO在某种程度上面临[a]问题."

          In your comments you suspected properly, that "PDO in some way is facing [a] problem when openssl_public_decrypt is used.."

          这篇关于PDO和openssl_public_decrypt失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆