Sage Pay v3.00 Integration

前端 未结 3 1804
萌比男神i
萌比男神i 2020-12-20 09:17

Can anyone help me incorporate the Sagepay v3.00 AES/CBC/PKCS#5 algorithm (encryption) into the following file. I\'m really struggling to understand how to include so that c

3条回答
  •  囚心锁ツ
    2020-12-20 09:47

    You could try this. I can't test it, so let me know how you get on.

    
        
        

    {$msg}

    EOT; } exit; // // ---------------- Additional functions ------------ // function simpleXor($InString, $Key) { $KeyList = array(); $output = ""; for($i = 0; $i < strlen($Key); $i++){ $KeyList[$i] = ord(substr($Key, $i, 1)); } for($i = 0; $i < strlen($InString); $i++) { $output.= chr(ord(substr($InString, $i, 1)) ^ ($KeyList[$i % strlen($Key)])); } return $output; } 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; } #added by Rik function addPKCS5Padding($input) { $blockSize = 16; $padd = ""; $length = $blockSize - (strlen($input) % $blockSize); for ($i = 1; $i <= $length; $i++) { $padd .= chr($length); } return $input . $padd; } function removePKCS5Padding($input) { $blockSize = 16; $padChar = ord($input[strlen($input) - 1]); $unpadded = substr($input, 0, (-1) * $padChar); return $unpadded; } function encryptAes($string, $key) { $string = addPKCS5Padding($string); $crypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string, MCRYPT_MODE_CBC, $key); return strtoupper(bin2hex($crypt)); } function decryptAes($strIn, $password) { #Sagepay specific - remove the '@' $strIn = substr($strIn,1) $strInitVector = $password; $strIn = pack('H*', $hex); $string = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $password, $strIn, MCRYPT_MODE_CBC,$strInitVector); return removePKCS5Padding($string); } ?>

提交回复
热议问题