HMAC File Checker based on SHA-256

Source: Internet
Author: User
Tags hash hmac md5

HMAC is the hash function with key, and the message Identification code (MAC) generated by it can be used to authenticate the message. Here I make a software that verifies the legality of a file. Let me briefly introduce the background knowledge of the software and then introduce its code implementation.

Introduction of Background knowledge

Sometimes the two sides of the communication, based on security considerations, need to check the message sent over to confirm that the message was not modified by a third party. This checksum can be done in this way:

The two parties agree on a key (that is, a password), which is confidential to the third party;

The sender of the message produces a check code for the message to be sent using the key pair and sends the check code together with the message;

The receiver of the message, after receiving the message with the check code, separates the message and the checkout code and generates a check code for the message with the key;

Then compares two checksum codes, if the same words are not modified by a third party, if the message is likely to be illegally modified (and also may be other reasons for the change of the message) then the message is not trustworthy, need the other side to send;

* Among them, the algorithm of generating check code generally uses HMAC, it ensures that the third party in the case of unknown key, it is impossible to modify the message can be modified at the same time to modify the check code to match the modified message.

* In the process of the message is public (unencrypted), the algorithm only provides the integrity of the message verification and does not provide confidentiality, confidentiality can be public key cryptography algorithm reality, this is not discussed here.

Second, the realization of software

I did it. The software is able to generate a checksum file on any file on the computer's disk. Vri (the key is entered by the user), according to the checksum file can be used to verify the corresponding files. The specific approach will be given in the following example.

The hash function of the HMAC algorithm in the program I am using the SHA-256 algorithm, which is more secure than MD5 and SHA-1. (In fact, because it is not a formal security product, so the use of MD5 or SHA-1 in this procedure is also not).

The structure of the *HMAC is shown in the following illustration:

Figure A structure of HMAC

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.