Sagepay错误 - 3045:缺少货币字段

时间:2015-05-12 11:15:29

标签: php sagepay

请不要将其标记为重复。我已经完成了同样问题的几乎所有上一篇文章,但无法解决我的错误 我正在尝试将Sagepay协议从v2.23升级到v3.00
我还部署了Sagepay提供的PHP工具包,并得到了同样的错误 下面是我使用的AES加密,使其与我的includes.php中的v3.00兼容 任何指导都将非常感谢。

<?


/* Base 64 Encoding function **
** PHP does it natively but just for consistency and ease of maintenance, let's declare our own function **/
function base64Encode($plain) {
  // Initialise output variable
  $output = "";

  // Do encoding
  $output = base64_encode($plain);

  // Return the result
  return $output;
}

/* Base 64 decoding function **
** PHP does it natively but just for consistency and ease of maintenance, let's declare our own function **/
function base64Decode($scrambled) {
  // Initialise output variable
  $output = "";

  // Fix plus to space conversion issue
  $scrambled = str_replace(" ","+",$scrambled);

  // Do encoding
  $output = base64_decode($scrambled);

  // Return the result
  return $output;
}


/*  The SimpleXor encryption algorithm                                                                                **
**  NOTE: This is a placeholder really.  Future releases of Form will use AES or TwoFish.  Proper encryption      **
**  This simple function and the Base64 will deter script kiddies and prevent the "View Source" type tampering        **
**  It won't stop a half decent hacker though, but the most they could do is change the amount field to something     **
**  else, so provided the vendor checks the reports and compares amounts, there is no harm done.  It's still          **
**  more secure than the other PSPs who don't both encrypting their forms at all                                      */

function simpleXor($InString, $Key) {
  // Initialise key array
  $KeyList = array();
  // Initialise out variable
  $output = "";

  // Convert $Key into array of ASCII values
  for($i = 0; $i < strlen($Key); $i++){
    $KeyList[$i] = ord(substr($Key, $i, 1));
  }

  // Step through string a character at a time
  for($i = 0; $i < strlen($InString); $i++) {
    // Get ASCII code from string, get ASCII code from key (loop through with MOD), XOR the two, get the character from the result
    // % is MOD (modulus), ^ is XOR
    $output.= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)]));
  }

  // Return the result
  return $output;
}


//** Wrapper function do encrypt an encode based on strEncryptionType setting **
function encryptAndEncode($strPost) {

        global $strEncryptionType
              ,$strEncryptionPassword;

        if ($strEncryptionType=="XOR") 
        {
                //** XOR encryption with Base64 encoding **
                return base64Encode(simpleXor($strPost,$strEncryptionPassword));
        } 
        else 
        {
                //** AES encryption, CBC blocking with PKCS5 padding then HEX encoding - DEFAULT **

                //** use initialization vector (IV) set from $strEncryptionPassword
        $strIV = $strEncryptionPassword;

        //** add PKCS5 padding to the text to be encypted
        $strPost = addPKCS5Padding($strPost);

        //** perform encryption with PHP's MCRYPT module
                $strCrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $strEncryptionPassword, $strPost, MCRYPT_MODE_CBC, $strIV);

                //** perform hex encoding and return
                return "@" . bin2hex($strCrypt);
        }
}


//** Wrapper function do decode then decrypt based on header of the encrypted field **
function decodeAndDecrypt($strPost) {

        global $strEncryptionPassword;

        if (substr($strPost,0,1)=="@") 
        {
                //** HEX decoding then AES decryption, CBC blocking with PKCS5 padding - DEFAULT **

                //** use initialization vector (IV) set from $strEncryptionPassword
        $strIV = $strEncryptionPassword;

        //** remove the first char which is @ to flag this is AES encrypted
        $strPost = substr($strPost,1); 

        //** HEX decoding
        $strPost = pack('H*', $strPost);

        //** perform decryption with 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 does not have built in PKCS5 Padding, so we use this
function addPKCS5Padding($input)
{
   $blocksize = 16;
   $padding = "";

   // Pad input to an even 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);
*************************/

?>

2 个答案:

答案 0 :(得分:0)

您检查过加密密码是否正确? 3045是密码错误时抛出的第一个错误。这听起来并不那么疯狂 - 加密密码在测试和现场之间是不同的.....

答案 1 :(得分:0)

问题在于我的服务器mcrypt PHP扩展。它不是在服务器上安装/启用。在进行所有测试尝试之前,我必须考虑这个问题。 感谢大家为我的问题付出的努力。