2011-04-17 60 views
2

我正在寻找加密密码字段以用于登录系统,因此我想匹配加密以确保用户输入了正确的详细信息。MD5或Silverlight中的其他加密C#

由于某些原因,Security.Cryptography在Silverlight中没有MD5服务,因此我正在寻找其他方法。

我以前用这个:

public string Md5Encrypt(string originalPassword) 
     { 
      //Declarations 
      Byte[] originalBytes; 
      Byte[] encodedBytes; 
      MD5 md5; 

      //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password) 
      md5 = new MD5CryptoServiceProvider(); 
      originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword); 
      encodedBytes = md5.ComputeHash(originalBytes); 

      //Convert encoded bytes back to a 'readable' string 
      return BitConverter.ToString(encodedBytes); 
     } 

但现在无法正常工作。

谁能给我在Silverlight C#工作加密方法的简单例子

感谢

+2

[MD5已被破坏](http://www.codeproject.com/KB/security/HackingMd5.aspx)。它不是**加密方法。这是一个哈希算法。与MD5类似,[也应避免使用SHA1](http://www.schneier.com/blog/archives/2005/02/sha1_broken.html)。 – pickypg 2011-04-17 18:09:45

回答

2

您可以简单地使用在Silverlight中使用HashLib:http://hashlib.codeplex.com/(看HashLib.HashFactory.HashCryptoNotBuildIn命名空间内)

另外BouncyCastle.Crypt 1.7释放具有一个Silverlight 2.0及以上的构建,其中最加密/散列函数:http://www.bouncycastle.org/csharp/

最后,为了您的解救,单声道源代码总是在这里解救您:https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Security.Cryptography/SHA512Managed.cs您可以将任何cypto代码复制到您的项目中,只要它的目标是.NET 2.0或更高版本。

+0

感谢您的选择,我会看看。 – 2011-04-17 18:26:00