Page 1 of 1

What could be wrong with my SSL encrypt call?

Posted: Tue May 17, 2011 7:13 pm
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);

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

Posted: Wed May 18, 2011 11:38 am
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.