Archive for December, 2006

Generate a MD5 string

December 15, 2006 Leave a comment

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: