The SHA algorithm is evolved on the basis of MD4, and a fixed-length summary information can be obtained by the SHA algorithm.
The SHA Algorithm series has SHA-1 (also known as Sha), sha-224,sha-256,sha-384, and SHA-512, which are usually named after the four algorithms in the following five algorithms and are called SHA-2 algorithms.
The difference between SHA and MD algorithms is mainly in the summary length, the summary length of SHA algorithm is longer, the security is higher
length description of the SHA algorithm
SHA algorithm implementation (similar to MD5 implementation)
1. MessageDigest Class of Java comes withNote: only supportsha-1,sha-256,sha-384 and SHA-512Using the Java-MessageDigest class implementation of the SHA and implementation of the MD5, the concrete implementation of the example code
/*** SHA1 Implementation message digest */Public static byte[] SHA1 () throws exception{messagedigest SHA1 = MessageDigest. getinstance ("SHA"); //Note here to fill Sha instead of SHA1 byte[] result = Sha1.digest ("China". GetBytes ("GBK"));System. out. println (result. Length); return result; } /*** SHA1 Implementation message digest */Public static byte[] SHA256 () throws exception{messagedigest SHA1 = MessageDigest. getinstance ("SHA-256"); //Other SHA2 algorithms in the same vein byte[] result = Sha1.digest ("China". GetBytes ("GBK"));System. out. println (result. Length); return result; } |
2.
Apache's Message Digest tool class Org.apache.commons.codec.digest.DigestUtils implementation digestutils. sha256 ("China". GetBytes ("GBK"));Other digest function names are used by analogy with the algorithm name
From for notes (Wiz)
SHA Information Summary