php - PDO and openssl_public_decrypt failing -
i trying decrypt , update password mysql database table. while doing giving me weird error.
php warning: pdo::exec(): ssl operation failed 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
- passwords encrypted using private key.
- openssl_private_encrypt function used encryption.
- decryption done using openssl_public_decrypt
- encryption along insertion databse works fine
- decryption along update not work. pdo::exec fails reason
- platform using ubuntu, php 5.6.24-1+deb.sury.org~xenial+1
- encrypt-insert, decrypt-update order of operations.
- mysql connection open before encryption , decryption performed
code encryption decryption:
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 problem appreciated.
code works:
$pdo = getmysqlpdoinstance(); //get pdo instance using ssl $id = 101; $plaintext = 'abcd'; $password = processplaintext($plaintext, 'encrypt'); $count = $pdo->exec(sprintf("update table set password = '%s' id = %d", $password, $id)); print("updated $count rows.\n");
code fails:
$pdo = getmysqlpdoinstance(); //get pdo instance using ssl $id = 101; $password = processplaintext($encryptedpassword, 'decrypt'); $count = $pdo->exec(sprintf("update table set password = '%s' id = %d", $password, $id)); print("updated $count rows.\n");
thanks
Comments
Post a Comment