Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static String SHA512(String input)
- {
- try {
- // getInstance() method is called with algorithm SHA-512
- MessageDigest md = MessageDigest.getInstance("SHA-512");
- // digest() method is called
- // to calculate message digest of the input string
- // returned as array of byte
- byte[] messageDigest = md.digest(input.getBytes());
- // Convert byte array into signum representation
- BigInteger no = new BigInteger(1, messageDigest);
- // Convert message digest into hex value
- String hashtext = no.toString(16);
- // Add preceding 0s to make it 32 bit
- while (hashtext.length() < 32) {
- hashtext = "0" + hashtext;
- }
- // return the HashText
- return hashtext;
- }
- // For specifying wrong message digest algorithms
- catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement