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:com.stratio.cassandra.index.schema.ColumnMapperBigInteger.java

/**
 * Returns the {@code String} representation of the specified {@link BigInteger}.
 *
 * @param bi The {@link BigInteger} to be converted.
 * @return The {@code String} representation of the specified {@link BigInteger}.
 *///w  w w  .  j  a  v  a2  s  .  c  o  m
private static String encode(BigInteger bi) {
    return bi.toString(Character.MAX_RADIX);
}

From source file:de.upb.wdqa.wdvd.revisiontags.SHA1Converter.java

private static String getBase(int base, byte[] bytes) {
    String result;/*from w w  w .ja  v a  2  s . com*/

    if (bytes != null) {
        if (bytes.length != 0) {
            BigInteger bi = new BigInteger(1, bytes);
            String tmp = bi.toString(base);

            int numberOfDigits = (int) Math.ceil(160.0 / (Math.log(base) / Math.log(2.0)));

            result = StringUtils.leftPad(tmp, numberOfDigits, '0');
        } else {
            result = "";
        }
    } else {
        result = null;
    }

    return result;
}

From source file:ezbake.warehaus.WarehausUtils.java

public static Text getKey(String uri) {
    try {//from  w  w  w  .j  a  v  a 2s .  c  o  m
        MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
        messageDigest.update(uri.getBytes());
        byte[] hash = messageDigest.digest();
        BigInteger bigInt = new BigInteger(1, hash);
        String hashtext = bigInt.toString(16);
        return new Text(hashtext + ":" + uri);
    } catch (NoSuchAlgorithmException e) {
        // We hopefully should never end up here
        logger.error("NoSuchAlgorithmException thrown while attempting " + "to hash key.", e);
        throw new RuntimeException(e);
    }
}

From source file:com.networknt.light.util.HashUtil.java

private static String toHex(byte[] array) throws NoSuchAlgorithmException {
    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 w  w  .  j  a v a2 s . c om*/
        return hex;
    }
}

From source file:MD5.java

public static String calculateMD5(File updateFile) {
    MessageDigest digest;// ww w.  j  a v a 2s  . co m
    try {
        digest = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        return null;
    }
    InputStream is;
    try {
        is = new FileInputStream(updateFile);
    } catch (FileNotFoundException e) {
        return null;
    }
    byte[] buffer = new byte[8192];
    int read;
    try {
        while ((read = is.read(buffer)) > 0) {
            digest.update(buffer, 0, read);
        }
        byte[] md5sum = digest.digest();
        BigInteger bigInt = new BigInteger(1, md5sum);
        String output = bigInt.toString(16);
        // Fill to 32 chars
        output = String.format("%32s", output).replace(' ', '0');
        return output;
    } catch (IOException e) {
        throw new RuntimeException("Unable to process file for MD5", e);
    } finally {
        try {
            is.close();
        } catch (IOException e) {
            System.out.println(e);
        }
    }
}

From source file:com.khipu.lib.java.KhipuService.java

private static String byteArrayToString(byte[] data) {
    BigInteger bigInteger = new BigInteger(1, data);
    String hash = bigInteger.toString(16);
    while (hash.length() < 64) {
        hash = "0" + hash;
    }/*from  w  w w .  j av  a  2s  . c o  m*/
    return hash;
}

From source file:shootersubdownloader.Shootersubdownloader.java

static String md5(byte[] bs) {
    try {/*from   w  w  w .ja  v  a  2  s .c o  m*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] messageDigest = md.digest(bs);
        BigInteger number = new BigInteger(1, messageDigest);
        String hashtext = number.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;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

From source file:shootersubdownloader.Shootersubdownloader.java

static String md5(String input) {
    try {//from   w w w . j a  va2 s .  c  o m
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] messageDigest = md.digest(input.getBytes());
        BigInteger number = new BigInteger(1, messageDigest);
        String hashtext = number.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;
    } catch (NoSuchAlgorithmException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.opendaylight.latency.util.LatencyPacketUtil.java

private static String bigIntegerToPaddedHex(final BigInteger dataPathId) {
    return StringUtils.leftPad(dataPathId.toString(16), 16, "0");
}

From source file:org.apache.cloudstack.utils.security.DigestHelper.java

private static String getPaddedDigestString(MessageDigest digest, BigInteger pwInt) {
    String checksum;//w w  w . j a  v  a2  s .  co m
    String pwStr = pwInt.toString(16);
    // we have half byte string representation, so
    int padding = 2 * digest.getDigestLength() - pwStr.length();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < padding; i++) {
        sb.append('0'); // make sure the MD5 password is 32 digits long
    }
    sb.append(pwStr);
    checksum = sb.toString();
    return checksum;
}