If you are calling ToString on a byte to co开发者_如何学运维nvert it to a 2 digit hex value does it matter if you use a format provide of CultureInfo.CurrentCulture or CultureInfo.InvariantCulture in any way?
Example:
public string CalculateMD5Hash(string input)
{
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
foreach (byte b in hash)
{
sb.Append(b.ToString("x2",CultureInfo.InvariantCulture));
}
return sb.ToString();
}
Basically can I leave out the IFormatProvider and always get the same result, or if I provide on of the CultureInfo defaults it will make a difference in the output?
Maybe, in the far far future we will have culturally dependent notations for Hex values. But today, no. You can safely omit the FormatProvider.
精彩评论