.Net create MD5 Hash tag

What is the proper way to create an md 5 hash tag
    Dim TerminalID As String = "33001"
    Dim OrderID As String = "12345"
    Dim Amount As String = "1.00"
    Dim Date_Time As String = System.DateTime.Now.ToString("dd-MM-yyyy:HH:mm:ss:fff", CultureInfo.InvariantCulture)
    Dim SecretKey As String = "SandboxSecret001"

Hash tag on the following combined strings.
TerminalID & OrderID & Amount & Date_Time & SecretKey
Larry Bristersr. DeveloperAsked:
Who is Participating?
 
David Johnson, CD, MVPConnect With a Mentor OwnerCommented:
You are mistaken there, you are confusing strTohash with strHashProof
Here is the modified code to show that it isn't just a simple concatenation
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ee_29073582
{
    class Program
    {
      
        static void Main(string[] args)
        {
            string strTerminalID = "33001Now is the time for all good men to come to the aid of the party";
            string strOrderID = "12345";
            string strAmount = "1.00";
            String Time = System.DateTime.Now.ToString("dd-MM-yyyy:HH:mm:ss:ff");
            String strSecretKey = "SandboxSecret001";
            string strtoHash;
            string strHash;
            Int32 HashLength;

            strtoHash = strTerminalID + strOrderID + strAmount + Time + strSecretKey;
            strHash = CalculateMD5Hash(strtoHash);
            Console.WriteLine(strHash);
            

            Console.WriteLine("The Hash is " + (strHash.Length).ToString() + " Characters");
            Console.ReadLine();
        }
        static string CalculateMD5Hash(string input)
        {
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
            {
                sb.Append(hash[i].ToString("X2"));
            }
            return sb.ToString();
        }
    }
}

Open in new window

0
 
David Johnson, CD, MVPOwnerCommented:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace ee_29073582
{
    class Program
    {
        static string CalculateMD5Hash(string input)
        {
            MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
            byte[] hash = md5.ComputeHash(inputBytes);
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < hash.Length; i++)
                {
                sb.Append(hash[i].ToString("X2"));
                }
            return sb.ToString();
        }
        static void Main(string[] args)
        {
            string strTerminalID = "33001";
            string strOrderID = "12345";
            string strAmount = "1.00";
            String Time = System.DateTime.Now.ToString("dd-MM-yyyy:HH:mm:ss:ff");
            String strSecretKey = "SandboxSecret001";
            string strtoHash;
            string strHash;
            strtoHash = strTerminalID + strOrderID + strAmount + Time + strSecretKey;
            strHash = CalculateMD5Hash(strtoHash);
            Console.WriteLine(strHash);
            Console.ReadLine();
        }

    }
}

Open in new window

0
 
Larry Bristersr. DeveloperAuthor Commented:
David,
That's not creating a hash... just the values strung together

I need a 32 character length md5 hash
0
 
Larry Bristersr. DeveloperAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.