2011-04-17 29 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