Skip to content

Instantly share code, notes, and snippets.

@mi-24v
Created April 23, 2016 17:17
Show Gist options
  • Save mi-24v/21d5ba02d3a415f7cfb3e640c45a2b09 to your computer and use it in GitHub Desktop.
Save mi-24v/21d5ba02d3a415f7cfb3e640c45a2b09 to your computer and use it in GitHub Desktop.
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