【问题标题】:Silverlight MD5 implementationSilverlight MD5 实施
【发布时间】:2011-05-18 14:23:54
【问题描述】:

我想使用 MD5 加密我的密码。我在谷歌上搜索并尝试了一些东西,但似乎它们不适用于我......

我正在使用 using System.Security.Cryptography 库。这显然是大多数人使用的。我有这个库,但是当我想使用时:

 MD5 md5Hasher = MD5.Create();

它给了我一个错误...

有人对 Silverlight 中的 MD5 有一些经验吗

欢迎帮助! :)

谢谢

【问题讨论】:

标签: silverlight encryption md5


【解决方案1】:

首先,MD5是哈希算法,不是加密算法……

如果你真的需要使用 MD5 算法,我没有给你任何解决方案。但是,如果你想使用比 MD5 更好的 SHA256 哈希算法,那么这里有一个代码示例:

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

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 2010-10-08
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    • 2022-07-16
    • 2011-10-09
    • 1970-01-01
    相关资源
    最近更新 更多