package fii.admission.hash;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Random;

/**
 * Created by andy on 20.05.2017.
 */
public class HashConvertor {
    private String str;
    private String hashType;

    public HashConvertor(String str) {
        this(str, "SHA-256");
    }

    public HashConvertor(String str , String hashType){
        this.str=str;
        this.hashType=hashType;
    }
    public String toString() {
        try {
            //Random rand = new Random();
            MessageDigest digest = MessageDigest.getInstance(this.hashType);
            SecureRandom random = new SecureRandom();
            String salt = new BigInteger(0x32, random).toString(0x20);
            String str = this.str + salt;
            byte[] hash = digest.digest(str.getBytes("UTF-8"));
            StringBuffer hexString = new StringBuffer();
            int lg = hash.length;
            for (int i = 0; i < lg; i++) {
                String hex = Integer.toHexString(0xff & hash[i]);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }

            return (hexString.toString() + salt);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}

@@ -1212,24 +1212,804 @@
          %7D%0A%0A
+            return (hexString.toString() + salt);%0A        %7D catch (Exception ex) %7B%0A            throw new RuntimeException(ex);%0A        %7D%0A    %7D%0A    public String toString(String salt) %7B%0A        try %7B%0A            //Random rand = new Random();%0A            MessageDigest digest = MessageDigest.getInstance(this.hashType);%0A            String str = this.str + salt;%0A            byte%5B%5D hash = digest.digest(str.getBytes(%22UTF-8%22));%0A            StringBuffer hexString = new StringBuffer();%0A            int lg = hash.length;%0A            for (int i = 0; i %3C lg; i++) %7B%0A                String hex = Integer.toHexString(0xff & hash%5Bi%5D);%0A                if (hex.length() == 1) %7B%0A                    hexString.append('0');%0A                %7D%0A                hexString.append(hex);%0A            %7D%0A%0A
             

Update HashConvertor.java