Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigInteger;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import java.util.ArrayList;
- public class Main {
- public static void main(String[] args) throws NoSuchAlgorithmException {
- String[] testStringArray = { "something","I don't know", "Bruhhh"};
- ArrayList<String> result =new ArrayList<>();
- if(args.length > 0){
- for (String arg : args) {
- result.add(encrypt(arg));
- }
- }else
- {
- for (String test: testStringArray) {
- result.add(encrypt(test));
- }
- }
- System.out.println(result);
- }
- public static String encrypt(String text){
- MessageDigest m = null;
- try {
- m = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- throw new RuntimeException(e);
- }
- m.reset();
- m.update(text.getBytes());
- byte[] digest = m.digest();
- BigInteger bigInt = new BigInteger(1,digest);
- String hashtext = bigInt.toString(16);
- // Now we need to zero pad it if you actually want the full 32 chars.
- while(hashtext.length() < 32 ){
- hashtext = "0"+hashtext;
- }
- return hashtext;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement