Problem with phpseclib and PDO

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

Problem with phpseclib and PDO

Postby Registration » Wed Nov 06, 2013 6:17 pm

Hi, i'm trying to pass a public_key recovered trough a PDO query to phpseclib, but i get the following error:
Code: Select all
Fatal error: Uncaught exception 'PDOException' with message 'You cannot serialize or unserialize PDO instances'


The code i actually use is:
Code: Select all
   $stmt = $pdo->prepare("SELECT public_key FROM users WHERE username = ?");
   $stmt->execute(array($seller));
   $row = $stmt->fetch();
   
      $public_key = $row['public_key'];
      $rsa = new Crypt_RSA();
      $rsa->loadKey($public_key);
      $ciphertext = base64_encode($rsa->encrypt($details));

}
Registration
Traveler
 
Posts: 1
Joined: Wed Nov 06, 2013 6:04 pm

Re: Problem with phpseclib and PDO

Postby TerraFrost » Thu Nov 07, 2013 2:54 am

Code: Select all
<?php
include('Crypt/RSA.php');

$pdo = new PDO('mysql:host=localhost;dbname=dbname', 'username', 'password');
$stmt = $pdo->prepare("SELECT '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4eCZ0
FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RKNUSesmQRMSGkVb1/
3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDyR4e9T04ZZwIDAQAB
-----END PUBLIC KEY-----' AS public_key");
$stmt->execute();
$row = $stmt->fetch();
   
$public_key = $row['public_key'];
$rsa = new Crypt_RSA();
$rsa->loadKey($public_key);

Does that work (well echo out the public key) for you? It works for me..
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am


Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 1 guest

cron