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.