MD5:
Private stringMD5 (stringsource) {StringBuilder SB=NewStringBuilder (); System.Security.Cryptography.MD5 MD5=System.Security.Cryptography.MD5.Create (); byte[] s =Md5.computehash (Encoding.UTF8.GetBytes (source)); for(inti =0; i < s.length; i++) {sb. Append (S[i]. ToString ("X2")); } returnsb. ToString (). ToLower (); }
HMAC_MD5:
Private stringHMAC_MD5 (stringKeystringmessage) {System.Text.ASCIIEncoding encoding=NewSystem.Text.ASCIIEncoding (); byte[] Keybyte =encoding. GetBytes (key); HMACMD5 HMACMD5=NewHMACMD5 (Keybyte); byte[] Messagebytes =encoding. GetBytes (message); byte[] Hashmessage =Hmacmd5.computehash (messagebytes); stringRtnval =bytetostring (hashmessage); returnRtnval.tolower (); } Private Static stringBytetostring (byte[] buff) { stringSBinary =""; for(inti =0; I < buff. Length; i++) {sbinary+ = Buff[i]. ToString ("X2"); } return(sbinary); }
HMAC_SHA1 Encryption:
/// <summary> ///HmacSHA1 mode for MACMACMAC signature/// </summary> /// <param name= "text" >Encrypted Content</param> /// <param name= "key" >Encrypt key</param> /// <returns></returns> Public stringHMACSHA1 (stringTextstringkey) {HMACSHA1 HMACSHA1=NewHMACSHA1 (); Hmacsha1. Key=Encoding.UTF8.GetBytes (key); byte[] DataBuffer =Encoding.UTF8.GetBytes (text); byte[] Hashbytes =Hmacsha1.computehash (DataBuffer); returnconvert.tobase64string (hashbytes); }
Various encryption algorithms