62,041
社区成员
发帖
与我相关
我的任务
分享
Dim hashPwd As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), _
System.Security.Cryptography.HashAlgorithm).ComputeHash(bytPwd)
'将密码转化为Hash安符串
Public Function ConPwdHashString(ByVal strPwd As String) As String
Dim sPwd As String
Dim bytPwd As [Byte]() = ConStrArr(strPwd)
Dim hashPwd As Byte() = CType(System.Security.Cryptography.CryptoConfig.CreateFromName("MD5"), _
System.Security.Cryptography.HashAlgorithm).ComputeHash(bytPwd)
sPwd = BitConverter.ToString(hashPwd)
Return sPwd
End Function
'将安符串转换为数组
Public Shared Function ConStrArr(ByVal s As [String]) As [Byte]()
Dim ca As [Char]() = s.ToCharArray()
Dim ba(ca.Length - 1) As [Byte]
Dim i As Integer
For i = 0 To ba.Length - 1
ba(i) = Convert.ToByte(ca(i))
Next i
Return ba
End Function 'ConvertStringToByteArray
private byte[] ConStrArr(string s)
{
char[] ca = s.ToCharArray();
byte[] ba = new byte[ca.Length - 1];
for (int i = 0; i < ba.Length-1; i++)
{
ba[i] = Convert.ToByte(ca[i]);
}
return ba;
}
public string ConPwdHashString(string strPwd)
{
string sPwd;
byte[] bytPwd = ConStrArr(strPwd);
byte[] hashPwd = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytPwd);
sPwd = BitConverter.ToString(hashPwd);
return sPwd;
}
byte[] hashPwd = ((System.Security.Cryptography.HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(bytPwd);