Detailed. NET encryption and decryption algorithm (1) hash encryption

Source: Internet
Author: User
Tags hash md5 net hash sha1

. NET has a wealth of encryption and decryption API library for our use, this blog summary. NET hash hash algorithm, and made into a simple demo, hope to be helpful to everyone.

MD5

Using System;  
Using System.Collections.Generic;  
Using System.Text;  
      
Using System.Security.Cryptography;  
      
Namespace Encryptanddecrypt  
{public  
    class MD5  
    {public  
        byte[] Hash (byte[] data)  
        {  
            System.Security.Cryptography.MD5 MD5 = System.Security.Cryptography.MD5.Create ();  
      
            return Md5.computehash (data);}}  

SHA1

Using System;  
Using System.Collections.Generic;  
Using System.Text;  
      
Using System.Security.Cryptography;  
      
Namespace Encryptanddecrypt  
{public  
    class SHA1  
    {public  
        byte[] Hash (byte[] data)  
        {  
            System.Security.Cryptography.SHA1 SHA1 = System.Security.Cryptography.SHA1.Create ();  
            return Sha1.computehash (data);}}  

SHA256

Using System;  
Using System.Collections.Generic;  
Using System.Text;  
      
Using System.Security.Cryptography;  
      
Namespace Encryptanddecrypt  
{public  
    class SHA256  
    {public  
      
      
        byte[] Hash (byte[] data)  
        {  
            System.Security.Cryptography.SHA256 sha256=  System.Security.Cryptography.SHA256.Create ();  
            return Sha256.computehash (data);}}  

SHA384

Using System;  
Using System.Collections.Generic;  
Using System.Text;  
      
Using System.Security.Cryptography;  
Namespace Encryptanddecrypt  
{public  
    class SHA384  
    {public  
      
        byte[] Hash (byte[] data)  
        {  
            System.Security.Cryptography.SHA384 sha384 = System.Security.Cryptography.SHA384.Create ();  
            return Sha384.computehash (data);}}  

SHA512

Using System;  
Using System.Collections.Generic;  
Using System.Text;  
      
Using System.Security.Cryptography;  
      
Namespace Encryptanddecrypt  
{public  
    class SHA512  
    {public  
      
        byte[] Hash (byte[] data)  
        {  
            System.Security.Cryptography.SHA512 sha512 = System.Security.Cryptography.SHA512.Create ();  
            return Sha512.computehash (data);}}  

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.