Error on Signing & Encrypting PayPal Website Payment Button with openssl_

From: Date: Sat, 24 Jul 2010 18:18:22 +0000
Subject: Error on Signing & Encrypting PayPal Website Payment Button with openssl_
Groups: php.general 
Request: Send a blank email to php-general+get-307134@lists.php.net to get a copy of this message
Hi, anyone has experience creating PayPal Encrypted Website Payment button? I follow PayPal SDK example but the encrypted value is not correct. I think the error should be with openssl_pkcs7_sign() since PayPal can decrypt it with PayPal private key but does not recognize my signed data. PayPal also told me that it is my encryption error. Please kindly advice on the code below. Thanks! Keith ___________________________________________________________________________________________ //$buttonParams is key=value pair string with \n separation between each key=value pair $mypub = 'file://'.realpath('./mypubcert.pem'); $myprv = 'file://'.realpath('./myprvkey.pem'); $paypalpubcert= 'file://'.realpath('./paypal_cert_pem.pem'); $dataStrFile = realpath(tempnam('./tmp', 'pp_')); $fd = fopen($dataStrFile, 'w'); fwrite($fd, $buttonParams); fclose($fd); $signedDataFile = realpath(tempnam('./tmp', 'pp_')); openssl_pkcs7_sign($dataStrFile, $signedDataFile, $mypub, $myprv,array(), PKCS7_BINARY); unlink($dataStrFile); $signedData = file_get_contents($signedDataFile); $signedDataArray = explode("\n\n", $signedData); //I don't understand why this code, just follow example only. $signedData = base64_decode($signedDataArray[1]); //I don't understand why this code, just follow example only. unlink($signedDataFile); $decodedSignedDataFile = realpath(tempnam('./tmp', 'pp_')); $fd = fopen($decodedSignedDataFile, 'w');fwrite($fd, $signedData); fclose($fd); $encryptedDataFile = realpath(tempnam('./tmp', 'pp_')); openssl_pkcs7_encrypt($decodedSignedDataFile, $encryptedDataFile, $paypalpubcert, array(), PKCS7_BINARY); unlink($decodedSignedDataFile); $encryptedData = file_get_contents($encryptedDataFile); unlink($encryptedDataFile); $encryptedDataArray = explode("\n\n", $encryptedData); $encryptedData = trim(str_replace("\n", '', $encryptedDataArray[1])); //why this? $encryptedData = "-----BEGIN PKCS7-----".$encryptedData."-----END PKCS7-----"; $encryptedBtn = "<form action='https://www.sandbox.paypal.com/cgi-bin/webscr' method='post'><input type='hidden' name='cmd' value='_s-xclick'><INPUT TYPE='hidden' NAME='encrypted' VALUE='$encryptedData'><input type='image' src='https://www.sandbox.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif' border='0' name='submit' alt='PayPal - The safer, easier way to pay online!'><img alt='' border='0' src='https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif' width='1' height='1'></form>"; echo $encryptedBtn ; _________________________________________________________________________________

« previous php.general (#307134) next »