Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    csharp
  » MD5 Encrypt String to 32 Character Hash
      by sde
 Page 1 of 1 
   

(Login to remove green text ads)
Snippet
This is more of a code snippet than an article, but I was looking for a way to match a php md5 encrypted string in C# and came up with this.
Code:
private string encryptString(string strToEncrypt) { System.Text.UTF8Encoding ue = new System.Text.UTF8Encoding(); byte[] bytes = ue.GetBytes(strToEncrypt); // encrypt bytes System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); byte[] hashBytes = md5.ComputeHash(bytes); // Convert the encrypted bytes back to a string (base 16) string hashString = ""; for(int i=0;i<hashBytes.Length;i++) { hashString += Convert.ToString(hashBytes[i],16).PadLeft(2,'0'); } return hashString.PadLeft(32,'0'); }
Sorry for the lack of comments, but hopefully this will help someone =)




 
 Page 1 of 1 
   

Rate This Article
1 2 3 4 5 6 7 8 9 10





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle