C # MD5 sha1 sha256 sha384 sha512 example Standard Edition flagship Edition

Source: Internet
Author: User
Tags sha1

 

Code

  //  If it is text, it is first converted into a byte sequence. If there are Chinese characters, do not use ASCII encoding, which will cause the Chinese characters to become question marks.  
Byte [] Buffer = Encoding. utf8.getbytes ( " HONG Xing's blog " ); // UTF-8 Coding
Buffer = Encoding. Default. getbytes ( " HONG Xing's blog " ); // GBK/gb2312 Encoding


// 16 bytes, 128 bits
Md5cryptoserviceprovider MD5 = New Md5cryptoserviceprovider ();
Byte [] H1 = Md5.computehash (buffer );


// 20 bytes, 160 characters
Sha1cryptoserviceprovider sha1 = New Sha1cryptoserviceprovider ();
Byte [] H2 = Sha1.computehash (buffer );


// 32 bytes, 256 bits
Sha256cryptoserviceprovider sha256 = New Sha256cryptoserviceprovider ();
Byte [] H3 = Sha256.computehash (buffer );


// 48 bytes, 384 characters
Sha384cryptoserviceprovider sha384 = New Sha384cryptoserviceprovider ();
Byte [] H4 = Sha384.computehash (buffer );


// 64-byte, 512-bit
Sha512cryptoserviceprovider sha512 = New Sha512cryptoserviceprovider ();
Byte [] H5 = Sha512.computehash (buffer );


String S1 = Bitconverter. tostring (H1). Replace ( " - " , String . Empty );
String S2 = Bitconverter. tostring (H2). Replace ( " - " , String . Empty );
String S3 = Bitconverter. tostring (H3). Replace ( " - " , String . Empty );
String S4 = Bitconverter. tostring (h4). Replace ( " - " , String . Empty );
String S5 = Bitconverter. tostring (H5). Replace ( " - " , String . Empty );


Console. writeline (S1 );
Console. writeline (S2 );
Console. writeline (S3 );
Console. writeline (S4 );
Console. writeline (S5 );

 

Test URL:

Http://www.hongcing.com/tool/md5

Http://www.hongcing.com/tool/sha1

Related Article

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.