SHA of Message digest algorithm for information encryption

Source: Internet
Author: User

SHA is an implementation of the Message digest algorithm, which has already summed up the implementation of MD2\4\5, and then summarizes SHA's implementation for you.

The JDK implementation of SHA:

Private Static void sha_jdk () {        try  {            = messagedigest.getinstance ("SHA");   We can get different message digest key             digest.update (Src.getbytes ()) through sha\sha-1\sha-384\sha-256\sha-512;            System.out.println ("SHA:" +hex.encodehexstring (Digest.digest ()));         Catch (nosuchalgorithmexception e) {            e.printstacktrace ();        }    }

The BC implementation of SHA:

Private Static void SHA_BC () {        new  sha1digest ();         0, Src.getbytes (). length);         byte New byte [Digest.getdigestsize ()];         0);        System.out.println ("shabyte:" +hex.encodehexstring (shabyte));    }

There is no implementation for the Sha224,java JDK, the following are the methods implemented using BC:

Private Static void SHA224_BC () {        new  sha224digest ();         0, Src.getbytes (). length);         byte New byte [Digest.getdigestsize ()];         0);        System.out.println ("sha224byte:" +hex.encodehexstring (sha224byte));    }

There is also a JDK-like implementation for SHA224:

Private Static void sha224_bc_jdk () {        security.addprovider(new  Bouncycastleprovider ());         Try {            = messagedigest.getinstance ("SHA-224");            Digest.update (Src.getbytes ());            System.out.println ("SHA224_BC_JDK:" +hex.encodehexstring (Digest.digest ()));         Catch (nosuchalgorithmexception e) {            e.printstacktrace ();        }    }

Finally, a brief introduction to the CC's SHA implementation:

private static void Sha_cc_byte () {System.out.println ("SHA_CC_BYTE_SHA1:" +digestutils.sha1hex (Src.getbytes ())); System.out.println ("sha_cc_byte_sha256:" +digestutils.sha256hex (Src.getbytes ())); System.out.println ("sha_cc_byte_sha384:" +digestutils.sha384hex (Src.getbytes ())); System.out.println ("sha_cc_byte_sha512:" +digestutils.sha512hex (Src.getbytes ()));} private static void Sha_cc () {System.out.println ("SHA_CC_SHA1:" +digestutils.sha1hex (SRC)); System.out.println ("sha_cc_sha256:" +digestutils.sha256hex (SRC)); System.out.println ("sha_cc_sha384:" +digestutils.sha384hex (SRC)); System.out.println ("sha_cc_sha512:" +digestutils.sha512hex (SRC));}

Here Sha's implementation summary is complete.

SHA of Message digest algorithm for information encryption

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.