将带有HASH MD5的字符串转换为ToBase64String [英] Convert string with HASH MD5 to ToBase64String
问题描述
这是我的问题,
我有这个代码接受干净的文本密码并返回Base64MD5哈希值
< pre $
private static string GetMd5Base64Pass(string userpwd)
{
MD5 md5 = new MD5CryptoServiceProvider();
return Convert.ToBase64String(md5.ComputeHash(Encoding.ASCII.GetBytes(userpwd)));
}
我需要重用它来接受MD5字符串散列并返回Base64MD5。
我试过这样做:
private static string GetMd5Base64PassMD5(字符串userpwd)
{
MD5 md5 = new MD5CryptoServiceProvider();
return Convert.ToBase64String(Encoding.ASCII.GetBytes(userpwd));
}
但收益完全不同。
已经试图将字符串转换为bytearray,不起作用。
我需要插入一个带有32位MD5的字符串,并将其返回到Base64String 。
thks
------------------ ------------编辑
示例:
密码为123123:
MD5是:4297f44b13955235245b2497399d7a93
MD5的Base64String是:Qpf0SxOVUjUkWySXOZ16kw ==
我需要得到
这个:Qpf0SxOVUjUkWySXOZ16kw ==
from
这个哈希字符串
4297f44b13955235245b2497399d7a93
public static string ConvertHexStringToBase64(string hexString)
{
byte [] buffer = new byte [hexString.Length / 2];
for(int i = 0; i< hexString.Length; i ++)
{
buffer [i / 2] = Convert.ToByte(Convert.ToInt32(hexString.Substring(i, 2),16));
i + = 1;
}
string res = Convert.ToBase64String(buffer);
return res;
}
接收md5字符串散列并将其转换为Base64十六进制
this is my problem,
i have this code that accepts clean text with passwords and returns Base64MD5 hashes
private static string GetMd5Base64Pass(string userpwd)
{
MD5 md5 = new MD5CryptoServiceProvider();
return Convert.ToBase64String(md5.ComputeHash(Encoding.ASCII.GetBytes(userpwd)));
}
And i need to reuse it to accept MD5 string hashes and return in Base64MD5.
i tried to do this:
private static string GetMd5Base64PassMD5(string userpwd)
{
MD5 md5 = new MD5CryptoServiceProvider();
return Convert.ToBase64String(Encoding.ASCII.GetBytes(userpwd));
}
but the returns are completely different.
already tried to convert the string to bytearray, didn't work.
I need to insert one string with 32bits MD5, and return it in Base64String.
thks
------------------------------ Edited
Example:
Password is 123123:
MD5 is: 4297f44b13955235245b2497399d7a93
Base64String of MD5 is: Qpf0SxOVUjUkWySXOZ16kw==
I need to get
this: Qpf0SxOVUjUkWySXOZ16kw==
from
this hash string 4297f44b13955235245b2497399d7a93
public static string ConvertHexStringToBase64(string hexString)
{
byte[] buffer = new byte[hexString.Length / 2];
for (int i = 0; i < hexString.Length; i++)
{
buffer[i / 2] = Convert.ToByte(Convert.ToInt32(hexString.Substring(i, 2), 16));
i += 1;
}
string res = Convert.ToBase64String(buffer);
return res;
}
this receives md5 string hashes and transforms it to Base64 Hex
这篇关于将带有HASH MD5的字符串转换为ToBase64String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!