C#: Den MD5 Hash eines Strings als String

Tags: .NET

public string getMD5Hash(string strSource)
{
	String strResult;

	if ((strSource == null) || (strSource.Length == 0))
	{
		strResult = string.Empty;
	}
	else
	{
		System.Security.Cryptography.MD5CryptoServiceProvider objMD5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
		byte[] arrTextToHash = Encoding.Default.GetBytes(strSource);
		byte[] arrResult = objMD5.ComputeHash(arrTextToHash);

		strResult = System.BitConverter.ToString(arrResult);
	}

	return strResult;
}
Add a Comment