Situatie
The SHA-2 family of cryptographic hash functions consists of six hash functions. These are:
- SHA-224, with 224 bit hash values
- SHA-256, with 256 bit hash values
- SHA-384, with 384 bit hash values
- SHA-512, with 512 bit hash values
- SHA-512/224, with 512 bit hash values
- SHA-512/256, with 512 bit hash valuesAmong these, SHA-256 and SHA-512 are the most commonly accepted and used hash functions computed with 32-bit and 64-bit words, respectively. SHA-224 and SHA-384 are truncated versions of SHA-256 and SHA-512 respectively, computed with different initial values.
Solutie
Pasi de urmat
To calculate cryptographic hashing value in Java, MessageDigest Class is used, under the package java.security.
MessagDigest Class provides following cryptographic hash function to find hash value of a text as follows:
- MD2
- MD5
- SHA-1
- SHA-224
- SHA-256
- SHA-384
- SHA-512
These algorithms are initialized in static method called getInstance(). After selecting the algorithm the message digest value is calculated and the results is returned as byte array. BigInteger class is used, to convert the resultant byte array into its signum representation. This representation is then converted into hexadecimal format to get the expected MessageDigest.
Below program shows the implementation of SHA-512 hash function:
Leave A Comment?