当前位置: 代码迷 >> ASP.NET >> membership的密码是如何加密的
  详细解决方案

membership的密码是如何加密的

热度:3379   发布时间:2013-02-25 00:00:00.0
membership的密码是怎么加密的
我用sha1加密怎么加密出来的不一样?

------解决方案--------------------------------------------------------
internal string EncodePassword(string pass, int passwordFormat, string salt)
{
if (passwordFormat == 0) // MembershipPasswordFormat.Clear
return pass;

byte[] bIn = Encoding.Unicode.GetBytes(pass);
byte[] bSalt = Convert.FromBase64String(salt);
byte[] bAll = new byte[bSalt.Length + bIn.Length];
byte[] bRet = null;

Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
if (passwordFormat == 1)
{ // MembershipPasswordFormat.Hashed
HashAlgorithm s = HashAlgorithm.Create(Membership.HashAlgorithmType);
bRet = s.ComputeHash(bAll);
}
else
{
bRet = EncryptPassword(bAll);
}

return Convert.ToBase64String(bRet);
}