Various encryption algorithms

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.