Created
April 23, 2016 17:17
-
-
Save mi-24v/21d5ba02d3a415f7cfb3e640c45a2b09 to your computer and use it in GitHub Desktop.
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 Conceal{ | |
| public static void main(String[] args){ | |
| if(args.length < 1){ | |
| System.err.println("Arguments must has 1 contents(Algorithm Name)."); | |
| System.exit(1); | |
| } | |
| System.out.print("password : "); | |
| String value = String.valueOf(System.console().readPassword()); | |
| System.out.println(encryptHashValue(args[0],value)); | |
| } | |
| public static String encryptHashValue(String algorithmName, String value){ | |
| MessageDigest md; | |
| StringBuilder sb; | |
| try{ | |
| md = MessageDigest.getInstance(algorithmName); | |
| }catch(NoSuchAlgorithmException e){ | |
| e.printStackTrace(); | |
| return null; | |
| } | |
| sb = new StringBuilder(); | |
| md.update(value.getBytes()); | |
| for(byte b : md.digest()){ | |
| sb.append(String.format("%02x",b)); | |
| } | |
| return sb.toString(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment