Checkout
Search…
4. Compute HASH

Hashing Methods

The parameter tampering attack is based on the manipulation of parameters exchanged between client and server in order to modify application data, such as user credentials, amount and quantity of products, etc.
C#
VB.Net
PHP
TypeScript
1
public string ComputeHash(Request _req)
2
{
3
string _key= { Secret Key Provided by OG}
4
string datatocomputeHash = quot;{_req.amount}{_req.authKey}{_req.currency}{_req.merchantCode}{_req.pc}{_req.referenceID}{_req.sourceCurrency}{_req.timeStamp}{_req.tunnel}{_req.userReference}";
5
return GetHashValue(datatocomputeHash, _key);
6
}
7
public string GetHashValue(String datatocomputeHash, String HashKey)
8
{
9
HMACSHA256 hmac = new HMACSHA256(System.Text.Encoding.UTF8.GetBytes(HashKey));
10
string computedHash = convertToHex(hmac.ComputeHash(System.Text.UTF8Encoding.Default.GetBytes(datatocomputeHash)));
11
return computedHash;
12
}
13
private string convertToHex(byte[] data)
14
{
15
System.Text.StringBuilder sb = new System.Text.StringBuilder(data.Length);
16
foreach (byte b in data)
17
sb.AppendFormat("{0:X2}", (int)b);
18
19
return sb.ToString();
20
}
Copied!
1
Private Function ComputeHash(ByVal _req As Request) As String
2
Dim _key As Strig={ Secret Key Provided by OG}
3
Dim datatocomputeHash As String = quot;{_req.amount}{_req.authKey}{_req.currency}{_req.merchantCode}{_req.pc}{_req.referenceID}{_req.sourceCurrency}{_req.timeStamp}{_req.tunnel}{_req.userReference}"
4
Return GetHashValue(datatoHash, _key)
5
End Function
6
7
Public Function GetHashValue(ByVal datatocomputeHash As String, ByVal HashKey As String) As String
8
Dim hmac As HMACSHA256 = New HMACSHA256(System.Text.Encoding.UTF8.GetBytes(HashKey))
9
Dim computedHash As String = convertToHex(hmac.ComputeHash(System.Text.UTF8Encoding.[Default].GetBytes(datatocomputeHash)))
10
Return computedHash
11
End Function
12
13
Private Function convertToHex(ByVal data As Byte()) As String
14
Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder(data.Length)
15
For Each b As Byte In data
16
sb.AppendFormat("{0:X2}", CInt(b))
17
Next
18
Return sb.ToString()
19
End Function
Copied!
1
private function ComputeHash(Request $req)
2
{
3
$_key= {Secret Key Provided by OG}
4
$datatocomputeHash = $_req.amount.$_req.authKey.$_req.currency.$_req.merchantCode.$_req.pc.$_req.referenceID.$_req.sourceCurrency.$_req.timeStamp.$_req.tunnel.$_req.userReference;
5
return GetHashValue($datatocomputeHash, $_key);
6
}
7
public function GetHashValue($datatocomputeHash,$HashKey)
8
{
9
$computedHash = strtoupper(hash_hmac("sha256", $datatocomputeHash,$HashKey));
10
return $computedHash
11
}
Copied!
1
private ComputeHash(_req: Request): string {
2
let _key={ Secret Key Provided by OG}
3
let datatocomputeHash: string = "{_req.amount}{_req.authKey}{_req.currency}{_req.merchantCode}{_req.pc}{_req.referenceID}{_req.sourceCurrency}{_req.timeStamp}{_req.tunnel}{_req.userReference}";
4
return GetHashValue(datatocomputeHash, _key);
5
}
6
7
public GetHashValue(datatocomputeHash: String, HashKey: String): string {
8
let hmac: HMACSHA256 = new HMACSHA256(System.Text.Encoding.UTF8.GetBytes(HashKey));
9
let computedHash: string = convertToHex(hmac.ComputeHash(System.Text.UTF8Encoding.Default.GetBytes(datatocomputeHash)));
10
return computedHash;
11
}
12
13
pagecode:` private string convertToHex(byte[] data)
14
{
15
System.Text.StringBuilder sb = new System.Text.StringBuilder(data.Length);
16
foreach (byte b in data)
17
sb.AppendFormat("{0:X2}", (int)b);
18
19
return sb.ToString();
20
}`;
Copied!

Copy link