Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String sha256(String string) {
- MessageDigest md;
- try {
- md = MessageDigest.getInstance("SHA-256");
- md.update(string.getBytes());
- byte byteData[] = md.digest();
- //convert the byte to hex format method 2
- StringBuffer hexString = new StringBuffer();
- for (int i=0;i<byteData.length;i++) {
- String hex=Integer.toHexString(0xff & byteData[i]);
- if(hex.length()==1) hexString.append('0');
- hexString.append(hex);
- }
- return hexString.toString();
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment