Hashing plays a crucial role in securing the integrity and authenticity of data exchanged within the payment API. In this document, we'll focus on utilizing the SHA-256 hashing algorithm, a widely adopted cryptographic hash function known for its strength and security.
Enable the hashing
Login to the portal with your credential, then access to you will see the option to enable hash for payment.
using System;
using System.Security.Cryptography;
using System.Text;
public class HashGenerator
{
public static string ComputeSHA256Hash(string input)
{
using (SHA256 sha256 = SHA256.Create())
{
byte[] inputBytes = Encoding.UTF8.GetBytes(input);
byte[] hashBytes = sha256.ComputeHash(inputBytes);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
builder.Append(hashBytes[i].ToString("x2"));
}
return builder.ToString();
}
}
}
Java:
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class HashGenerator {
public static String computeSHA256Hash(String input) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hashBytes = digest.digest(input.getBytes());
StringBuilder builder = new StringBuilder();
for (byte b : hashBytes) {
builder.append(String.format("%02x", b));
}
return builder.toString();
}
}