using System;
using System.Text;
using System.Security.Cryptography ;
namespace hex_cs
{
/// <summary>
/// Summary description for clsHash.
/// </summary>
public class clsHash
{
public clsHash()
{
//
// TODO: Add constructor logic here
//
}
/*
public string encryptPassMD5(string strPass)
{
return
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(
strPass,
"MD5");
}
public string encryptPassSHA1(string strPass)
{
return
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(
strPass,
"SHA1");
}
*/
public string MD5 (string strInput_plainText)
{
/// Convert plain text into a byte array.
byte[] buffer = Encoding.UTF8.GetBytes(strInput_plainText);
System.Security.Cryptography.MD5CryptoServiceProvider check;
check = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] somme = check.ComputeHash (buffer);
return Convert.ToBase64String(buffer);
}
public string GetMD5(string strPlain)
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] HashValue, MessageBytes = UE.GetBytes(strPlain);
MD5 md5 = new MD5CryptoServiceProvider();
string strHex = "";
HashValue = md5.ComputeHash(MessageBytes);
foreach(byte b in HashValue)
{
strHex += String.Format("{0:x2}", b);
}
return strHex;
} /* GetMD5 */
public string GetSHA1(string strPlain)
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] HashValue, MessageBytes = UE.GetBytes(strPlain);
SHA1Managed SHhash = new SHA1Managed();
string strHex = "";
HashValue = SHhash.ComputeHash(MessageBytes);
foreach(byte b in HashValue)
{
strHex += String.Format( "{0:x2}" , b);
}
return strHex;
} /* GetSHA1 */
public string GetSHA256(string strPlain)
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] HashValue, MessageBytes = UE.GetBytes(strPlain);
SHA256Managed SHhash = new SHA256Managed();
string strHex = "";
HashValue = SHhash.ComputeHash(MessageBytes);
foreach(byte b in HashValue)
{
strHex += String.Format("{0:x2}", b);
}
return strHex;
} /* GetSHA256 */
public string GetSHA384(string strPlain)
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] HashValue, MessageBytes = UE.GetBytes(strPlain);
SHA384Managed SHhash = new SHA384Managed();
string strHex = "";
HashValue = SHhash.ComputeHash(MessageBytes);
foreach(byte b in HashValue)
{
strHex += String.Format("{0:x2}", b);
}
return strHex;
} /* GetSHA384 */
public string GetSHA512(string strPlain)
{
UnicodeEncoding UE = new UnicodeEncoding();
byte[] HashValue, MessageBytes = UE.GetBytes(strPlain);
SHA512Managed SHhash = new SHA512Managed();
string strHex = "";
HashValue = SHhash.ComputeHash(MessageBytes);
foreach(byte b in HashValue)
{
strHex += String.Format("{0:x2}", b);
}
return strHex;
} /* GetSHA512 */
}
}