2017-10-21 4 views
0

チェックサムの生成と支払いトランザクションの検証のためにノードJで次の関数を書き直そうとしています。ノードJS内の指定された文字列のチェックサムを生成して確認する方法

私はNode Jsに変換する必要があるService Provideのコードを入手しました。私はバックエンドとしてエクスプレスを使用しています。

<?php 

    function generateChecksum($transId,$sellingCurrencyAmount,$accountingCurrencyAmount,$status, $rkey,$key) 
    { 
     $str = "$transId|$sellingCurrencyAmount|$accountingCurrencyAmount|$status|$rkey|$key"; 
     $generatedCheckSum = md5($str); 
     return $generatedCheckSum; 
    } 

    function verifyChecksum($paymentTypeId, $transId, $userId, $userType, $transactionType, $invoiceIds, $debitNoteIds, $description, $sellingCurrencyAmount, $accountingCurrencyAmount, $key, $checksum) 
    { 
     $str = "$paymentTypeId|$transId|$userId|$userType|$transactionType|$invoiceIds|$debitNoteIds|$description|$sellingCurrencyAmount|$accountingCurrencyAmount|$key"; 
     $generatedCheckSum = md5($str); 
//  echo $str."<BR>"; 
//  echo "Generated CheckSum: ".$generatedCheckSum."<BR>"; 
//  echo "Received Checksum: ".$checksum."<BR>"; 
     if($generatedCheckSum == $checksum) 
      return true ; 
     else 
      return false ; 
    } 
?> 

どのようにパラメータを渡して次のコードをJavascriptで記述できますか?

+0

は、いくつかのMD5の実装のために、この[SO](https://stackoverflow.com/questions/14733374/how-to-generate-md5-file-hash-on-javascript)質問を見てください。 –

答えて

0
var crypto = require('crypto'); 
function generateChecksum(transId,sellingCurrencyAmount,accountingCurrencyAmount,status, rkey,key) 
{ 
    var str = `${transId}|${sellingCurrencyAmount}|${accountingCurrencyAmount}|${status}|${rkey}|${key}`; 
    var generatedCheckSum = crypto.createHash('md5').update(str).digest("hex"); 
    return generatedCheckSum; 
} 

function verifyChecksum(paymentTypeId, transId, userId, userType, transactionType, invoiceIds, debitNoteIds, description, sellingCurrencyAmount, accountingCurrencyAmount, key, checksum) 
{ 
    var str = `${paymentTypeId}|${transId}|${userId}|${userType}|${transactionType}|${invoiceIds}|${debitNoteIds}|${description}|${sellingCurrencyAmount}|${accountingCurrencyAmount}|${key}`; 
    var generatedCheckSum = crypto.createHash('md5').update(str).digest("hex"); 

    if(generatedCheckSum == checksum) 
     return true ; 
    else 
     return false ; 
} 
関連する問題