突然想在WP上用MD5 ,c#的MD5方法在SL下是不能用的额
搜索下MSDN,找到解决方法:
http://archive.msdn.microsoft.com/SilverlightMD5
下载那两个类添加到工程中,然后添加代码:
1: protected string GetMD5Hash(string input)
2: {
3: byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
4: MD5Managed md5 = new MD5Managed();
5: byte[] hash = md5.ComputeHash(bs);
6:
7: StringBuilder sb = new StringBuilder();
8: foreach (byte b in hash)
9: {
10: sb.Append(b.ToString("x2").ToLower());
11: }
12: return sb.ToString();
13: }
使用的时候调用这个函数就OK了
比如:
1: MessageBox.Show (GetMD5Hash("Hello World"));
效果: