Example usage for java.math BigInteger toString

List of usage examples for java.math BigInteger toString

Introduction

In this page you can find the example usage for java.math BigInteger toString.

Prototype

public String toString(int radix) 

Source Link

Document

Returns the String representation of this BigInteger in the given radix.

Usage

From source file:Main.java

public static String md5Calc(File f) {
    int i;//  w w  w  .ja v a 2 s .c o m

    byte[] buffer = new byte[1024];
    int read = 0;
    String md5hash;
    try {
        MessageDigest digest = MessageDigest.getInstance("MD5");
        InputStream is = new FileInputStream(f);
        while ((read = is.read(buffer)) > 0) {
            digest.update(buffer, 0, read);
        }
        byte[] md5sum = digest.digest();
        BigInteger bigInt = new BigInteger(1, md5sum);
        md5hash = bigInt.toString(16);
        is.close();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    if (md5hash.length() != 33) {
        String tmp = "";
        for (i = 1; i < (33 - md5hash.length()); i++) {
            tmp = tmp.concat("0");
        }
        md5hash = tmp.concat(md5hash);
    }

    return md5hash;
}

From source file:HashUtil.java

public static String getMD5(final String data) {
    try {/*from  w w w  .j ava  2s  .  co m*/
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.reset();
        m.update(data.getBytes());
        BigInteger bigInt = new BigInteger(1, m.digest());
        String hashtext = bigInt.toString(16);
        while (hashtext.length() < 32) {
            hashtext = "0" + hashtext;
        }
        return hashtext;
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return e.getMessage();
    }
}

From source file:support.AuthManager.java

public static String md5Custom(String st) {
    MessageDigest messageDigest = null;
    byte[] digest = new byte[0];

    try {/*from  www  .java2  s.c  o m*/
        messageDigest = MessageDigest.getInstance("MD5");
        messageDigest.reset();
        messageDigest.update(st.getBytes(StandardCharsets.UTF_8));
        digest = messageDigest.digest();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    BigInteger bigInt = new BigInteger(1, digest);
    String md5Hex = bigInt.toString(16);

    while (md5Hex.length() < 32) {
        md5Hex = "0" + md5Hex;
    }

    return md5Hex;
}

From source file:baldrickv.s3streamingtool.Hash.java

public static String hash(String algo, int output_bits, byte b[], int offset, int size) {
    try {/*w  w  w  . ja v a2  s .c om*/
        int output_bytes = output_bits / 4; //hex = 4 bits per byte
        MessageDigest sig = MessageDigest.getInstance(algo);
        sig.update(b, offset, size);
        byte d[] = sig.digest();

        StringBuffer s = new StringBuffer(output_bytes);
        BigInteger bi = new BigInteger(1, d);
        s.append(bi.toString(16));
        while (s.length() < output_bytes) {
            s.insert(0, '0');
        }
        return s.toString();
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(-1);
        return null;
    }

}

From source file:com.alibaba.otter.shared.common.utils.ByteUtils.java

public static String bigIntToHex(BigInteger big) {
    return big.toString(16);
}

From source file:com.jopss.logico.negocio.util.CriptoUtils.java

public static String md5Encrypt(String texto) {
    String encripted = null;/*from  w  ww. ja va 2  s  .  co m*/
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(texto.getBytes());
        BigInteger hash = new BigInteger(1, md.digest());
        encripted = hash.toString(16);
    } catch (NoSuchAlgorithmException e) {
        log.error(e);
    }
    return encripted;
}

From source file:com.gmu.uav.RadioSecurity.java

public static String toHex(byte[] array) {
    BigInteger bi = new BigInteger(1, array);
    String hex = bi.toString(16);
    int paddingLength = (array.length * 2) - hex.length();
    if (paddingLength > 0)
        return String.format("%0" + paddingLength + "d", 0) + hex;
    else// w  ww  .  j a  v a 2  s.c  o m
        return hex;
}

From source file:com.algodefu.yeti.md5.MD5HashGenerator.java

public static String generateKeyByString(String string) {
    MessageDigest m = null;/*from   www .  j ava2 s  .  c om*/
    try {
        m = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.reset();
    m.update(string.getBytes());
    byte[] digest = m.digest();
    BigInteger bigInt = new BigInteger(1, digest);
    String hashtext = bigInt.toString(16);
    while (hashtext.length() < 32) {
        hashtext = "0" + hashtext;
    }
    return hashtext;
}

From source file:com.algodefu.yeti.md5.MD5HashGenerator.java

public static String generateKeyByObject(Object object) {
    MessageDigest m = null;/*from  w  w  w .  j  a  va 2s  . c o m*/
    try {
        m = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.reset();
    //m.update(objectToByteArray(object));
    m.update(SerializationUtils.serialize((Serializable) object));
    byte[] digest = m.digest();
    BigInteger bigInt = new BigInteger(1, digest);
    String hashtext = bigInt.toString(16);
    while (hashtext.length() < 32) {
        hashtext = "0" + hashtext;
    }
    return hashtext;
}

From source file:org.nuxeo.ecm.core.management.statuses.NuxeoInstanceIdentifierHelper.java

public static String summarize(String value) throws NoSuchAlgorithmException {
    byte[] digest;
    digest = MessageDigest.getInstance(HASH_METHOD).digest(value.getBytes());
    BigInteger sum = new BigInteger(digest);
    return sum.toString(16);
}