. NET encryption and decryption--hash operations

Source: Internet
Author: User


One, the characteristics of the hash operation

1 , the hash operation is irreversible, and the hash operation can be understood as one-way encryption;


2 , any two different files, even if there is only a single byte of nuance, the resulting summaries are completely distinct. The significance of this feature is that it can be used to determine whether a message has been tampered with, that is, to resolve the integrity problem.


3 , regardless of the size of the original message, the summary information of the operation is fixed length, and the length of the summary differs according to the hash algorithm.





Second, the process of judging whether a message has been tampered with hash operation


1 , send a lil bit message for hashing, get a message digest, send a message and digest, and describe the hashing algorithm used to get the digest.


2 , the receiver obtains the message and the original digest, hashes the received message using the same hashing algorithm, and gets a summary again.


3 , comparing the original digest and the Local digest, if two are the same, the message was not tampered with, otherwise it was thought to have been tampered with.





Three. NET to implement the hash operation demo



Namespace hash operation {//ordinary hash operation class public class Hashalgorithmtype {Public Const string SHA1 = "SHA1";        Public Const string SHA256 = "SHA256";        Public Const string SHA384 = "SHA384";        Public Const string SHA512 = "SHA512";               Public Const string MD5 = "MD5";            } class Program {static void Main (string[] args) {string plaintext = "Hello,world"; Initializes the object HashAlgorithm ALG = Hashalgorithm.create (HASHALGORITHMTYPE.SHA1);                      SHA1Managed ALG = new sha1managed (); KeyedHashAlgorithm ALG = new HMACSHA1 (Encoding.Default.GetBytes ("Secret key Data");//Key hash operation, one more key parameter//to turn the string            Change to byte array byte[] Plaindata = Encoding.Default.GetBytes (plaintext); Get Digest byte[] Hashdata = alg.                ComputeHash (plaindata);//Here the parameter is a byte array or a stream//output result foreach (Byte b in Hashdata) {            Console.Write ("{0:x2}", b); }        }    }}




Four, analyze the security hidden trouble of hashing operation


If, during the process of sending a message, the information is intercepted by a third party, the original message and message digest are made, the original message is changed, the message digest is recalculated and sent, and the receiver does not notice that the message has been tampered with. And, in the process of sending messages, the information is not encrypted, the third party can see the message content, does not have confidentiality.









. NET encryption and decryption--hash operations

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.