We Recommend

Accelerated C# 2008 Accelerated C# 2008
This book is both a rapid tutorial and a permanent reference. You’ll quickly master C# syntax while learning how the CLR simplifies many programming tasks. You’ll also learn best practices that ensure your code will be efficient, reusable, and robust. Why spend months or years discovering the best ways to design and code C# when this book will show you how to do things the right way, right from the start?


Posted By

jags_sonawane on 02/13/08


Tagged

Encryption


Versions (?)


Encryption of string


Published in: C# 


  1. public static byte[] encryptData(string data)
  2. {
  3. System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
  4. byte[] hashedBytes;
  5. System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
  6. hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
  7. return hashedBytes;
  8. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: AndrewVos on April 16, 2008

This is hashing not encryption. There's no way to get the string back.

You could use: System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password,"md5") if you just want to hash a password.

You need to login to post a comment.