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