Home > Uncategorized > Hash codes for Realex payment processing

Hash codes for Realex payment processing

Might be of interest to anybody using the Realex payment system in ASP.NET / C#, this is the code to generate MD5 checksums for it:

 // Create an md5 sum string of this string
        static public string GetMd5Sum(string str)
        {
            // First we need to convert the string into bytes, which
            // means using a text encoder.
            Encoder enc = System.Text.Encoding.ASCII.GetEncoder();
            // Create a buffer large enough to hold the string
            byte[] unicodeText = new byte[str.Length];
            enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
            // Now that we have a byte array we can ask the CSP to hash it
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(unicodeText);
            // Build the final string by converting each byte
            // into hex and appending it to a StringBuilder
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < result.Length; i++)
            {
                sb.Append(result[i].ToString("X2"));
            }
            // And return it
            return sb.ToString().ToLower();
        }

Advertisement
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: