What could be wrong with my SSL encrypt call?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stokestack
Forum Newbie
Posts: 14
Joined: Thu Sep 16, 2010 2:37 am

What could be wrong with my SSL encrypt call?

Post by Stokestack »

Hi all. I'm having problems encrypting with RSA on both the client and server side. To troubleshoot, I just wanted to encrypt a test string. But the resulting encrypted version is empty, no matter what I do.

The public key here ($pubKey) is good; I had additional lines to test whether it was null. Thanks for any insight!

Code: Select all

$pubKey = openssl_get_publickey($pubKeyPEM);
$fh = fopen("encryptIDTest.log", 'w') or die("can't open file");
openssl_public_encrypt("D4DD101E-7BC0-4B97-A111-CBD62F908581", $pubEncrypted, $pubKey, OPENSSL_PKCS1_OAEP_PADDING);
fwrite($fh, "Test ID encrypted: {$pubEncrypted}\n");
fclose($fh);
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: What could be wrong with my SSL encrypt call?

Post by Jonah Bron »

What happens when you use OPENSSL_NO_PADDING? Also, (at least some of) the bytes produced in the encryption won't be valid characters, so it's best to encode it with base64_encode(). That will make it URL safe, too.
Post Reply