.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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
David Johnson, CD, MVPOwnerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Larry Bristersr. DeveloperAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.