C # - a variable using the Encrypt md5
Posted
by Guilherme Cardoso
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Guilherme Cardoso
Published on Tue, 25 May 2010 15:06:20 GMT
Indexed on
2010/05/25
16:11 UTC
Read the original article
Hit count: 466
When we are dealing with more sensitive data and important as a keyword, it is not appropriate at all stores them in database without encrypting for security reasons. For this we use MD5
MD5 is an algorithm that allow us to encript an string, but doesn't leave us desencrypt it (not sure if it is already possible, but at least I know there are many databases already having a record).
The method below will return us a variable encrypted with md5. For example: md5_encriptar (pontonetpt.com ");
The result will be: 34efe85d338075834ad41803eb08c0df
This way we save tthese encrypted data into a database, and then to make comparisons we often use the method to compare with the records kept.
public string md5_encrypt(string md5) { System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] bs = System.Text.Encoding.UTF8.GetBytes(md5); bs = x.ComputeHash(bs); System.Text.StringBuilder s = new System.Text.StringBuilder(); foreach (byte b in bs) { s.Append(b.ToString("x2").ToLower()); } string password = s.ToString(); return password; }
© Geeks with Blogs or respective owner