php - Sagepay Error - 3045 : The Currency field is missing -
please not mark duplicate. have gone through previous post same issue, not able tackle error.
trying upgrade sagepay protocol v2.23 v3.00
have deployed php kit provided sagepay , getting same error.
below aes encryption using make compatible v3.00 in includes.php
guidance appreciated.
<? /* base 64 encoding function ** ** php natively consistency , ease of maintenance, let's declare our own function **/ function base64encode($plain) { // initialise output variable $output = ""; // encoding $output = base64_encode($plain); // return result return $output; } /* base 64 decoding function ** ** php natively consistency , ease of maintenance, let's declare our own function **/ function base64decode($scrambled) { // initialise output variable $output = ""; // fix plus space conversion issue $scrambled = str_replace(" ","+",$scrambled); // encoding $output = base64_decode($scrambled); // return result return $output; } /* simplexor encryption algorithm ** ** note: placeholder really. future releases of form use aes or twofish. proper encryption ** ** simple function , base64 deter script kiddies , prevent "view source" type tampering ** ** won't stop half decent hacker though, change amount field ** ** else, provided vendor checks reports , compares amounts, there no harm done. it's still ** ** more secure other psps don't both encrypting forms @ */ function simplexor($instring, $key) { // initialise key array $keylist = array(); // initialise out variable $output = ""; // convert $key array of ascii values for($i = 0; $i < strlen($key); $i++){ $keylist[$i] = ord(substr($key, $i, 1)); } // step through string character @ time for($i = 0; $i < strlen($instring); $i++) { // ascii code string, ascii code key (loop through mod), xor two, character result // % mod (modulus), ^ xor $output.= chr(ord(substr($instring, $i, 1)) ^ ($keylist[$i % strlen($key)])); } // return result return $output; } //** wrapper function encrypt encode based on strencryptiontype setting ** function encryptandencode($strpost) { global $strencryptiontype ,$strencryptionpassword; if ($strencryptiontype=="xor") { //** xor encryption base64 encoding ** return base64encode(simplexor($strpost,$strencryptionpassword)); } else { //** aes encryption, cbc blocking pkcs5 padding hex encoding - default ** //** use initialization vector (iv) set $strencryptionpassword $striv = $strencryptionpassword; //** add pkcs5 padding text encypted $strpost = addpkcs5padding($strpost); //** perform encryption php's mcrypt module $strcrypt = mcrypt_encrypt(mcrypt_rijndael_128, $strencryptionpassword, $strpost, mcrypt_mode_cbc, $striv); //** perform hex encoding , return return "@" . bin2hex($strcrypt); } } //** wrapper function decode decrypt based on header of encrypted field ** function decodeanddecrypt($strpost) { global $strencryptionpassword; if (substr($strpost,0,1)=="@") { //** hex decoding aes decryption, cbc blocking pkcs5 padding - default ** //** use initialization vector (iv) set $strencryptionpassword $striv = $strencryptionpassword; //** remove first char @ flag aes encrypted $strpost = substr($strpost,1); //** hex decoding $strpost = pack('h*', $strpost); //** perform decryption php's mcrypt module return mcrypt_decrypt(mcrypt_rijndael_128, $strencryptionpassword, $strpost, mcrypt_mode_cbc, $striv); } else { //** base 64 decoding plus xor decryption ** return simplexor(base64decode($strpost),$strencryptionpassword); } } //** php's mcrypt not have built in pkcs5 padding, use function addpkcs5padding($input) { $blocksize = 16; $padding = ""; // pad input block size boundary $padlength = $blocksize - (strlen($input) % $blocksize); for($i = 1; $i <= $padlength; $i++) { $padding .= chr($padlength); } return $input . $padding; } /************* function pkcs5_pad($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); //echo "<br/>padding:".str_repeat(chr($pad), $pad)."<"; return $text . str_repeat(chr($pad), $pad); } function encryptfielddata($input) { $key = "[mykey]"; $iv = $key; $cipher = mcrypt_module_open(mcrypt_rijndael_128, "", mcrypt_mode_cbc, ""); if (mcrypt_generic_init($cipher, $key, $iv) != -1) { $ciphertext = mcrypt_generic($cipher,$input ); mcrypt_generic_deinit($cipher); $enc = bin2hex($ciphertext); } return $enc; } $str = "currency=gbp"; $datapadded = pkcs5_pad($str,16); $cryptpadded = "@" . encryptfielddata($datapadded); *************************/ ?>
have checked encryption password correct? 3045 first error thrown if password wrong. not nuts sounds - encryption passwords different between test , live.....
rik
Comments
Post a Comment