Message Digest Java.security.MessageDigest

Source: Internet
Author: User

This is a technique used in conjunction with message authentication codes to ensure message integrity. The main use of one-way hash function algorithm, can be used to verify the integrity of the message, and by hashing the password directly in the form of text preservation, etc., the current widely used algorithms have MD4, MD5, sha-1,jdk1.5 to support the above, the message digest in Java is very simple, Java.security.MessageDigest provides an easy way to do this:

/** *messagedigestexample.java *copyright 2005-2-16 */import Java.sec Urity. MessageDigest; /** * A single message digest algorithm that does not use a password. Can be used to hide a clear text message (such as: password) Save */public class messagedigestexample{public static void Main (string[] args) thr    oWS exception{if (args.length!=1) {System.err.println ("Usage:java messagedigestexample text");   System.exit (1); }
byte[] Plaintext=args[0].getbytes ("UTF8");
//use getinstance ("algorithm") to get a message digest, using SHA-1 's 160-bit algorithm messagedigest messagedigest= Messagedigest.getinstance ("SHA-1");   
System.out.println ("\ n" Messagedigest.getprovider (). GetInfo ());   Start using algorithm messagedigest.update (plaintext);   System.out.println ("\ndigest:");  Output algorithm operation result System.out.println (new String (Messagedigest.digest (), "UTF8")); } }

You can also use the message authentication code for the encryption implementation, JAVAX.CRYPTO.MAC provides a solution, interested people can refer to the relevant API documentation, this article is simply to explain what is a digest algorithm.

Message Digest Java.security.MessageDigest

Related Article

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.