Silverlight MD5 implementation
I want to encrypt my passwords by using MD5. I searched on google and tried a few things, but it seems like they don't work with me...
I'm using the using System.Security.Cryptography library. That's what most of the people use apparently. I have this library, but when I want to use:
MD5 m开发者_JAVA百科d5Hasher = MD5.Create();
it gives me an error...
Has anybody have some experience with MD5 in Silverlight
Help is welcome! :)
Thanks
First of all, MD5 is a hash algorithm, not an encryption algorithm...
If you really need to use the MD5 algorithm, I don't have any solution for you. However, if you want to use the SHA256 hash alogorithm, which is better than the MD5, then here's a code sample:
Public Function Hash(ByVal stringToHash As String) As String
Dim returnValue As String = ""
Dim unicodeEncoding As New System.Text.UnicodeEncoding
Dim bytesToHash() As Byte
Dim hashAlgorithm As System.Security.Cryptography.HashAlgorithm
Dim hashBytes() As Byte
'Get the bytes to hash
If String.IsNullOrEmpty(stringToHash) Then
bytesToHash = unicodeEncoding.GetBytes("")
Else
bytesToHash = unicodeEncoding.GetBytes(stringToHash)
End If
'Get the hashAlgorithm
hashAlgorithm = New System.Security.Cryptography.SHA256Managed
'Hash the bytes and convert it to string
hashBytes = hashAlgorithm.ComputeHash(bytesToHash)
returnValue = Convert.ToBase64String(hashBytes)
Return returnValue
End Function
http://blogs.msdn.com/b/delay/archive/2010/12/06/hash-for-the-holidays-managed-implementation-of-crc32-and-md5-algorithms-updated-new-release-of-computefilehashes-for-silverlight-wpf-and-the-command-line.aspx
精彩评论