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