function sign($data,$iv,$hexKey){
$_cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$binKey32 = hex2bin($hexKey);
$block = mcrypt_get_block_size('des', MCRYPT_MODE_CBC);
$pad = $block - (strlen($data) % $block);
$data .= str_repeat(chr($pad), $pad);
mcrypt_generic_init($_cipher, $hexKey, $iv);
$result = mcrypt_generic($_cipher, $data);
mcrypt_generic_deinit($_cipher);
return strtoupper(substr(bin2hex($result),0,32));
}
問題是,如果我調用此函數,例如:
$sign = sign("string", "strinGGnirts", "1234567812345678123456781234567812345678123456781234567812345678");
此錯誤occurrs:(在功能第三參數)
mcrypt_generic_init():密鑰太大;提供的長度:64,最大值:32
第三個參數是靜態鍵,它必須是64個字符長的字符串。它不能少。我試圖改變MCRYPT_RIJNDAEL_128
FOR MCRYPT_RIJNDAEL_256
但這個錯誤occurrs後(在函數第二個參數)
mcrypt_generic_init():㈣尺寸不正確;提供的長度:16,需要:32
我希望是誰的人會幫我:)
編輯:
整個測試文件:
<?php
function sign($data,$iv,$hexKey){
$_cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$binKey32 = hex2bin($hexKey);
$block = mcrypt_get_block_size('des', MCRYPT_MODE_CBC);
$pad = $block - (strlen($data) % $block);
$data .= str_repeat(chr($pad), $pad);
mcrypt_generic_init($_cipher, $binKey32, $iv);
$result = mcrypt_generic($_cipher, $data);
mcrypt_generic_deinit($_cipher);
return strtoupper(substr(bin2hex($result),0,32));
}
$sign = sign("demoOMED"."10.50"."EUR"."10000"."Michal"."Test"."2015-05-05 14:57:13", "demoOMEDDEMOomed", "1234567812345678123456781234567812345678123456781234567812345678");
print_r($sign);?>
<form method="post" action="https://doxxsl-staging.24-pay.eu/pay_gate/paygt" >
<input type="hidden" name="Mid" value="demoOMED">
<input type="hidden" name="EshopId" value="11111111">
<input type="hidden" name="PreAuthProvided" value="false">
<input type="hidden" name="MsTxnId" value="10000">
<input type="hidden" name="Amount" value="10.50">
<input type="hidden" name="CurrAlphaCode" value="EUR">
<input type="hidden" name="ClientId" value="170">
<input type="hidden" name="FirstName" value="Michal">
<input type="hidden" name="FamilyName" value="Test">
<input type="hidden" name="Email" value="[email protected]">
<input type="hidden" name="Street" value="Kalov">
<input type="hidden" name="Zip" value="01001">
<input type="hidden" name="City" value="Žilina">
<input type="hidden" name="Country" value="SVK">
<input type="hidden" name="Timestamp" value="2015-05-05 14:57:13">
<input type="hidden" name="Sign" value="<?php echo $sign;?>">
<!-- PARAMETER DEBUG USE ONLY WHILE TESTING -->
<input type="hidden" name="Debug" value="true">
<input type="submit" value="Test">
有了這些數據我得到輸出在Sign功能:6C4BBF9D2EC23D03E010AA94B5A7E174(INCORRECT)
隨着柵測試環境相同的數據登錄:FCBA944122EF996CE6E50B6229753CA7(正確)
編輯:
http://i.imgur.com/hNkuRoq.png
EDIT2:文檔作爲圖像
一部分,他們已經發出我新(工作)類,所以也許它會幫助別人:) http://pastebin.com/DKiXPMiE
這是我需要使用的一個支付門的開發者的功能。實際上我需要相同的輸出,但我需要可以工作的功能。由於沒有正確的輸出,我無法進入大門。所以我不能用更好的加密或類似的東西來實現功能。 – UareBugged
他們正在談論它的一部分文檔。該標誌應該如何看起來像http://i.imgur.com/hNkuRoq.png。關鍵是那64個字符長的第三個參數。 IV是第二個參數。它只是字符串+反轉字符串。第一個參數只是幾個字符串的組合 – UareBugged
http://stackoverflow.com/a/1628177/5006740 – strangeqargo