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