【问题标题】:Need to make changes to security algorithms from md5 to SHA-256 HMAC php需要将安全算法从 md5 更改为 SHA-256 HMAC php
【发布时间】: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 开发的“新手”,使用加密原语和信用卡支付可能不是一个好主意。只是我的两分钱。

标签: php md5 sha256


【解决方案1】:

你为什么要更改整个代码..

只需将md5 函数更改为sha

if (strlen($SECURE_SECRET) > 0) {
  $vpcURL .= "&vpc_SecureHash=" . strtoupper(md5($md5HashData));
}

if (strlen($SECURE_SECRET) > 0) {
  $vpcURL .= "&vpc_SecureHash=" . strtoupper(sha1($md5HashData));
}

【讨论】:

  • 感谢您的建议,但是收到 HTTP 状态 - 400 错误...
猜你喜欢
  • 2017-03-13
  • 2016-04-29
  • 1970-01-01
  • 2016-06-12
  • 2012-07-07
  • 1970-01-01
  • 2013-01-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多