Skip to main content

.net 2.0哈希字符串

存储用户密码到数据库,一般都要求先对密码字符串加密。在.net中常用的是MD5、SHA等不可逆的HASH算法。using System.Security.Cryptography;

private string EncodePassword(string password, string hashType)
{
  HashAlgorithm hash = HashAlgorithm.Create(hashType);
    byte[] bytes = Encoding.Unicode.GetBytes(password);
    byte[] inArray = hash.ComputeHash(bytes);

  return Convert.ToBase64String(inArray);
}

可选的HASH类型有:"SHA","SHA1","MD5","SHA256","SHA384","SHA512"

好像通杀: 2.0, 1.1, 1.0。我在2.0下测试通过。

Comments

Popular posts from this blog

PSP 三国无双 大蛇传 人物图片

PSP三国无双 大蛇传 人物图片(Google Picasa相册) 现在还不全,太多了。。。(2008-03-23) 搞完了,体力活啊。(2008-04-20) 暂时放弃吧,那个空间到期很久了,忘了更新这里了。什么时候找到地方放再跟新。(2009-04-29) 上传到Google Picasa(2009-09-25)

一点感想

久久没来,最近在家google基本无法使用了,无奈用自由门翻墙而出,看到自己以前所发的东西,感慨良多。想起硬盘上魔兽截图无数,说不定哪天出个意外,不如发帖留恋。