Created
September 3, 2018 15:52
-
-
Save gtomek/c7d0439ec7a975b4bcf43af57d6742f0 to your computer and use it in GitHub Desktop.
md5 generator in java from https://stackoverflow.com/questions/25838473/what-does-0xff-do-and-md5-structure
This file contains hidden or 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.MessageDigest; | |
| import java.security.NoSuchAlgorithmException; | |
| public class JavaMD5 { | |
| public static void main(String[] args) { | |
| String passwordToHash = "MyPassword123"; | |
| String generatedPassword = null; | |
| try { | |
| MessageDigest md = MessageDigest.getInstance("MD5"); | |
| md.update(passwordToHash.getBytes()); | |
| byte[] bytes = md.digest(); | |
| StringBuilder sb = new StringBuilder(); | |
| for (int i = 0; i < bytes.length; i++) { | |
| sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1)); | |
| } | |
| generatedPassword = sb.toString(); | |
| } catch (NoSuchAlgorithmException e) { | |
| e.printStackTrace(); | |
| } | |
| System.out.println(generatedPassword); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment