C#调用Java MD5加密 转换成base64编码

发布时间 2023-08-03 11:55:56作者: 懂你++

public byte[] GetUTF8(string content)
{
byte[] bytes = Encoding.UTF8.GetBytes(content);
return bytes;
}

public byte[] GetHash(byte[] sources)
{
MD5CryptoServiceProvider MD5CSP = new MD5CryptoServiceProvider();
byte[] targets = MD5CSP.ComputeHash(sources);
return targets;
}

public string ConvertBase64(byte[] sources)
{
string value = Convert.ToBase64String(sources);
return value;
}

string body="hello234";

string data_digest = ConvertBase64(GetHash(GetUTF8(body + "key123")));