【发布时间】:2017-04-08 11:23:08
【问题描述】:
我是 Web 开发领域的新手,一位朋友要求我将他们的支付网关从 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">
如何在我的代码中使用它?
如果你能在我应该改变的地方写下正确的代码吗?
【问题讨论】:
-
如果您是安全和 Web 开发的“新手”,使用加密原语和信用卡支付可能不是一个好主意。只是我的两分钱。