SHA and sha of message digest algorithm for Information Encryption

Source: Internet
Author: User

SHA and sha of message digest algorithm for Information Encryption

SHA is an implementation method of the message digest algorithm. The implementation of MD2 \ 4 \ 5 has been summarized earlier. Next, we will summarize the implementation of SHA.

Jdk Implementation of SHA:

Private static void SHA_JDK () {try {MessageDigest digest = MessageDigest. getInstance ("SHA"); // we can get different message digest keys digest through SHA \ SHA-1 \ SHA-384 \ SHA-256 \ SHA-512. update (src. getBytes (); System. out. println ("SHA:" + Hex. encodeHexString (digest. digest ();} catch (NoSuchAlgorithmException e) {e. printStackTrace ();}}

Sha bc implementation:

private static void SHA_BC(){        Digest digest = new SHA1Digest();        digest.update(src.getBytes(), 0, src.getBytes().length);        byte[] shaByte = new byte[digest.getDigestSize()];        digest.doFinal(shaByte, 0);        System.out.println("shaByte : "+Hex.encodeHexString(shaByte));    }

JAVA jdk does not provide implementation for shares'. The following is a method implemented using BC:

private static void SHA224_BC(){        Digest digest = new SHA224Digest();        digest.update(src.getBytes(), 0, src.getBytes().length);        byte[] sha224Byte = new byte[digest.getDigestSize()];        digest.doFinal(sha224Byte, 0);        System.out.println("sha224Byte : "+Hex.encodeHexString(sha224Byte));    }

There is also a JDK-like Implementation Method for shares:

private static void SHA224_BC_JDK(){        Security.addProvider(new BouncyCastleProvider());        try {            MessageDigest digest = MessageDigest.getInstance("SHA-224");            digest.update(src.getBytes());            System.out.println("SHA224_BC_JDK :"+Hex.encodeHexString(digest.digest()));        } catch (NoSuchAlgorithmException e) {            e.printStackTrace();        }    }

Finally, we will briefly introduce the SHA implementation of CC:

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));}

The SHA implementation is summarized here.

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.