需要将安全算法从 md5 更改为 SHA-256 HMAC php
Need to make changes to security algorithms from md5 to SHA-256 HMAC php
我是网络开发领域的新手,一位朋友要求我将他们的支付网关从 md5 升级到 SHA-256 HMAC。
我尝试自己更改它,但是在转到安全网关时出现错误,我认为我的代码中存在一些我不太理解的问题
现有代码:
if($type == "Credit Card") {
unset($_POST["type"]);
unset($_POST["order_id"]);
$SECURE_SECRET = "MIGS_SS";
$vpcURL = $_POST["virtualPaymentClientURL"] . "?";
unset($_POST["SubButL"]);
unset($_POST["virtualPaymentClientURL"]);
$md5HashData = $SECURE_SECRET;
ksort ($_POST);
$appendAmp = 0;
foreach($_POST as $key => $value) {
if (strlen($value) > 0) {
if ($appendAmp == 0) {
$vpcURL .= urlencode($key) . '=' . urlencode($value);
$appendAmp = 1;
} else {
$vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
}
$md5HashData .= $value;
}
}
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
}
header("Location: ".$vpcURL);
} else {
header("Location: index.php?dz=eft&id=".$order_id."\n\n");
}
我得到的新密码:
foreach($_POST as $key => $value) {
// create the hash input and URL leaving out any fields that have no value
if (strlen($value) > 0) {
?>
<input type="hidden" name="<?php echo($key); ?>" value="<?php echo($value); ?>"/><br>
<?php
if ((strlen($value) > 0) && ((substr($key, 0,4)=="vpc_") || (substr($key,0,5) =="user_"))) {
$hashinput .= $key . "=" . $value . "&";
}
}
}
$hashinput = rtrim($hashinput, "&");
?>
<!-- attach SecureHash -->
<input type="hidden" name="vpc_SecureHash" value="<?php echo(strtoupper(hash_hmac('SHA256', $hashinput, pack('H*',$securesecret)))); ?>"/>
<input type="hidden" name="vpc_SecureHashType" value="SHA256">
如何在我的代码中使用它?
如果你能在这里写出正确的代码我应该改变什么?
为什么要更改整个代码..
只需将 md5
函数更改为 sha
。
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
}
到
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(sha1($md5HashData));
}
我是网络开发领域的新手,一位朋友要求我将他们的支付网关从 md5 升级到 SHA-256 HMAC。
我尝试自己更改它,但是在转到安全网关时出现错误,我认为我的代码中存在一些我不太理解的问题
现有代码:
if($type == "Credit Card") {
unset($_POST["type"]);
unset($_POST["order_id"]);
$SECURE_SECRET = "MIGS_SS";
$vpcURL = $_POST["virtualPaymentClientURL"] . "?";
unset($_POST["SubButL"]);
unset($_POST["virtualPaymentClientURL"]);
$md5HashData = $SECURE_SECRET;
ksort ($_POST);
$appendAmp = 0;
foreach($_POST as $key => $value) {
if (strlen($value) > 0) {
if ($appendAmp == 0) {
$vpcURL .= urlencode($key) . '=' . urlencode($value);
$appendAmp = 1;
} else {
$vpcURL .= '&' . urlencode($key) . "=" . urlencode($value);
}
$md5HashData .= $value;
}
}
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
}
header("Location: ".$vpcURL);
} else {
header("Location: index.php?dz=eft&id=".$order_id."\n\n");
}
我得到的新密码:
foreach($_POST as $key => $value) {
// create the hash input and URL leaving out any fields that have no value
if (strlen($value) > 0) {
?>
<input type="hidden" name="<?php echo($key); ?>" value="<?php echo($value); ?>"/><br>
<?php
if ((strlen($value) > 0) && ((substr($key, 0,4)=="vpc_") || (substr($key,0,5) =="user_"))) {
$hashinput .= $key . "=" . $value . "&";
}
}
}
$hashinput = rtrim($hashinput, "&");
?>
<!-- attach SecureHash -->
<input type="hidden" name="vpc_SecureHash" value="<?php echo(strtoupper(hash_hmac('SHA256', $hashinput, pack('H*',$securesecret)))); ?>"/>
<input type="hidden" name="vpc_SecureHashType" value="SHA256">
如何在我的代码中使用它?
如果你能在这里写出正确的代码我应该改变什么?
为什么要更改整个代码..
只需将 md5
函数更改为 sha
。
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
}
到
if (strlen($SECURE_SECRET) > 0) {
$vpcURL .= "&vpc_SecureHash=" . strtoupper(sha1($md5HashData));
}