Example usage for java.math BigInteger BigInteger

List of usage examples for java.math BigInteger BigInteger

Introduction

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

Prototype

private BigInteger(byte[] magnitude, int signum) 

Source Link

Document

This private constructor is for internal use and assumes that its arguments are correct.

Usage

From source file:org.confab.Utilities.java

public static String md5(String pass) {
    String md5 = "";
    try {/*from   w w w .  j a va 2 s.c  om*/
        MessageDigest m = MessageDigest.getInstance("MD5");
        byte[] data = pass.getBytes();
        m.update(data, 0, data.length);
        BigInteger i = new BigInteger(1, m.digest());
        md5 = String.format("%1$032x", i);
    } catch (NoSuchAlgorithmException e) {
        System.out.println(e);
    }
    return md5;
}

From source file:Gestores.GestorHash.java

public String md5(String plaintext) {
    String hashtext = "";
    try {/*from w ww.  java2 s . c  o  m*/
        MessageDigest m = MessageDigest.getInstance("MD5");
        m.reset();
        m.update(plaintext.getBytes());
        byte[] digest = m.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        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;
        }
    } catch (NoSuchAlgorithmException ex) {
        Logger.getLogger(GestorHash.class.getName()).log(Level.SEVERE, null, ex);
    }
    return hashtext;
}

From source file:org.jongo.mocks.UserMock.java

public static UserMock getRandomInstance() {
    final UserMock instance = new UserMock();
    instance.name = new BigInteger(100, random).toString(32);
    instance.age = 1 + (int) (Math.random() * ((100 - 1) + 1));
    instance.birthday = dateFTR.parseDateTime(getRandomBirthDate());
    instance.lastupdate = new DateTime();
    instance.credit = new BigDecimal(random.nextDouble());
    return instance;
}

From source file:support.AuthManager.java

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

    try {// w w  w. jav a  2s. 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:com.examples.with.different.packagename.ClassNumberUtils.java

public static BigInteger createBigInteger(final String str) {
    if (str == null) {
        return null;
    }/*  ww  w.  ja  v  a 2s.c o m*/
    int pos = 0; // offset within string
    int radix = 10;
    boolean negate = false; // need to negate later?
    if (str.startsWith("-")) {
        negate = true;
        pos = 1;
    }
    if (str.startsWith("0x", pos) || str.startsWith("0X", pos)) { // hex
        radix = 16;
        pos += 2;
    } else if (str.startsWith("#", pos)) { // alternative hex (allowed by Long/Integer)
        radix = 16;
        pos++;
    } else if (str.startsWith("0", pos) && str.length() > pos + 1) { // octal; so long as there are additional digits
        radix = 8;
        pos++;
    } // default is to treat as decimal

    final BigInteger value = new BigInteger(str.substring(pos), radix);
    return negate ? value.negate() : value;
}

From source file:com.collaide.fileuploader.helper.TestHelper.java

protected static String getRandomString() {
    return new BigInteger(130, new SecureRandom()).toString(32);
}

From source file:Main.java

public static String createSirfCommandFromPayload(String payload) {
    int length = payload.length() / 2;
    String res;/*w  w  w .  j a  va 2 s .  co m*/

    byte[] command = new BigInteger(payload, 16).toByteArray();

    int checkSum = 0;
    for (byte b : command) {
        checkSum += (b & 0xff);
    }
    checkSum &= 0x7FFF;

    res = String.format((Locale) null, "%s%04X%s%04X%s", start, length, payload, checkSum, end);
    return res;
}

From source file:com.gwtcx.server.util.Security.java

public static String md5(final String text) {
    String hashword = null;//from   ww w. j  av  a  2 s  .  co  m

    try {
        final MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(text.getBytes());
        final BigInteger hash = new BigInteger(1, md5.digest());
        hashword = hash.toString(16);
    } catch (final NoSuchAlgorithmException nsae) {
    }

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

    return hashword;
}

From source file:org.rivetlogic.utils.IntegrationUtils.java

public static String MD5(String str) throws NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance("MD5");

    byte[] dg = digest.digest(str.getBytes());

    BigInteger number = new BigInteger(1, dg);

    return number.toString(16);
}

From source file:eml.studio.shared.util.Aes.java

/** 
 * Convert byte[] to a variety of hexadecimal strings
 *  //from   w  ww . j ava  2 s .  co  m
 * @param bytes byte[] 
 * @param radix Convertible rangefrom Character.MIN_RADIX to Character.MAX_RADIX out of range is changed to decimal
 * @return converted string 
 */
public static String binary(byte[] bytes, int radix) {
    return new BigInteger(1, bytes).toString(radix);
}