Created
December 21, 2010 16:25
-
-
Save avilches/750151 to your computer and use it in GitHub Desktop.
How to encode a hex SHA256 in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.*; | |
public class Sha { | |
public static String hash256(String data) throws NoSuchAlgorithmException { | |
MessageDigest md = MessageDigest.getInstance("SHA-256"); | |
md.update(data.getBytes()); | |
return bytesToHex(md.digest()); | |
} | |
public static String bytesToHex(byte[] bytes) { | |
StringBuffer result = new StringBuffer(); | |
for (byte byt : bytes) result.append(Integer.toString((byt & 0xff) + 0x100, 16).substring(1)); | |
return result.toString(); | |
} | |
} |
Is there a possibility of reversing it using SHA ?? If yes can you share some code snippets . !
yes! good gist. I had validated just now.
hash value -> string(?)-> base64
How do base64 conversion?
For base64: https://www.owasp.org/index.php/Hashing_Java
BASE64Decoder decoder = new BASE64Decoder();
return decoder.decodeBuffer(data);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you!