svdragster

SHA-256

Feb 21st, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. public String sha256(String string) {
  2. MessageDigest md;
  3. try {
  4. md = MessageDigest.getInstance("SHA-256");
  5. md.update(string.getBytes());
  6.  
  7. byte byteData[] = md.digest();
  8.  
  9. //convert the byte to hex format method 2
  10. StringBuffer hexString = new StringBuffer();
  11. for (int i=0;i<byteData.length;i++) {
  12. String hex=Integer.toHexString(0xff & byteData[i]);
  13. if(hex.length()==1) hexString.append('0');
  14. hexString.append(hex);
  15. }
  16. return hexString.toString();
  17. } catch (NoSuchAlgorithmException e) {
  18. e.printStackTrace();
  19. return null;
  20. }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment