Mac Information Summary

Source: Internet
Author: User
Tags sha1

MAC (Message authentication code, messaging authentication Code algorithm) is a key hash function algorithm that is compatible with the features of the MD and SHA algorithms, and the key is added on this basis. Therefore, the Mac is also called an HMAC. the MAC algorithm sets up two series of Message digest Algorithms, MD and SHA. MD series has HmacMD2, HmacMD4, HmacMD5 three kinds of algorithms. The SHA series hasHmacSHA1,HmacSHA224,HmacSHA256,HmacSHA384,HmacSHA512 These five kinds of algorithms. The length of the MAC algorithm summary value is the length of the specific digest algorithm. such as HmacMD5 even if the digest value of the corresponding MD5 algorithm is 128 bits long. Specific as follows:

implementation of MAC algorithm 1. Java Self-band class implementation       Note: Java Automatic classes only supportHmacMD5,HmacSHA1,HmacSHA256,HmacSHA384,HmacSHA512 These algorithms       The MAC algorithm is a message digest algorithm with a key, so its implementation is divided into two steps 1) to create the key 2) to obtain the Message digest implementation code as follows:
       /*** 1. Create key         */         //create a corresponding digest algorithm (such as md5\sha1\sha256, etc.) key generator object Keygenerator keygenerator keygenerator = keygenerator. getinstance ("HmacMD5");         //Generate key Secretkey Secretkey = Keygenerator.generatekey ();         //The byte array to get the key //byte[] key = secretkey.getencoded ();                 /*** 2. Generate Mac summary based on key         */         //Create a Mac instance object that corresponds to a digest algorithm (such as md5\sha1\sha256, etc.) Mac Mac = Mac. getinstance (Secretkey.getalgorithm ());         //Initialize the key of the Mac instance object Mac.init (secretkey);         //Get mac summary information byte[]result = mac.dofinal ("China". GetBytes ());System. Out. println (tohexstring(Result));






From for notes (Wiz)

Mac Information Summary

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.