Home > Visual C# > Generate a MD5 string

Generate a MD5 string

In any systems, you must design an user authentication to check if an user has a right permission to log in, at that time user’s information as password must be enscripted. With .NET, you can use one of two algorithms, SHA1 or MD5, to generate an enscripted result. These algorithms allow you to get a 32bits, 64bits or 128bit string with inputted characters and there is no way to descript because these algorithms are only one-way

Here is a short script that can help you to create a enscripted string using C#

String resultPassword;
Byte[] data;
MD5 hashMd5 = new MD5CryptoServiceProvider();
data = hashMD5.ComputeHash(Encoding.ASCII.GetBytes(inputPassword.ToCharArray()));
for (int i = 0; i < data.Length-1; i++)
resultPassword += data[i].ToString("X2");

After finishing FOR loop….you can get your enscripted string with “resultPassword”. Please remember to import System.Security.Cryptography library before executing

Categories: Visual C# Tags:
  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 )

Google+ photo

You are commenting using your Google+ 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: