Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public static String SHA512(String input)
  2. {
  3. try {
  4. // getInstance() method is called with algorithm SHA-512
  5. MessageDigest md = MessageDigest.getInstance("SHA-512");
  6.  
  7. // digest() method is called
  8. // to calculate message digest of the input string
  9. // returned as array of byte
  10. byte[] messageDigest = md.digest(input.getBytes());
  11.  
  12. // Convert byte array into signum representation
  13. BigInteger no = new BigInteger(1, messageDigest);
  14.  
  15. // Convert message digest into hex value
  16. String hashtext = no.toString(16);
  17.  
  18. // Add preceding 0s to make it 32 bit
  19. while (hashtext.length() < 32) {
  20. hashtext = "0" + hashtext;
  21. }
  22.  
  23. // return the HashText
  24. return hashtext;
  25. }
  26.  
  27. // For specifying wrong message digest algorithms
  28. catch (NoSuchAlgorithmException e) {
  29. throw new RuntimeException(e);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement