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:Main.java

private static String digest(final String value) {
    final byte[] digested;
    try {/*  ww w  .  j a va 2  s . c  om*/
        digested = MessageDigest.getInstance(HASH_ALGORITHM).digest(value.getBytes(CHARSET));
    } catch (final NoSuchAlgorithmException e) {
        return null;
    } catch (final UnsupportedEncodingException e) {
        return null;
    }

    final String hashed = new BigInteger(1, digested).toString(16);
    final int padding = HASH_LENGTH - hashed.length();
    if (padding == 0) {
        return hashed;
    }

    final char[] zeros = new char[padding];
    Arrays.fill(zeros, '0');
    return new StringBuilder(HASH_LENGTH).append(zeros).append(hashed).toString();
}

From source file:Main.java

public static String md5(String input) {
    String result = input;/*from   ww  w.j  ava2 s  . com*/
    if (input != null) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(input.getBytes());
            BigInteger hash = new BigInteger(1, md.digest());
            result = hash.toString(16);
            if ((result.length() % 2) != 0) {
                result = "0" + result;
            }
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
    return result;
}

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

public static String md5Encrypt(String texto) {
    String encripted = null;//from w ww .  ja  v  a2 s  . c  o  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:Main.java

public static String generateSecureKey() {
    return new BigInteger(512, random).toString(32);
}

From source file:net.maritimecloud.identityregistry.utils.PasswordUtil.java

public static String generatePassword() {
    SecureRandom secRandom = new SecureRandom();
    return new BigInteger(130, secRandom).toString(32);
}

From source file:Main.java

public static String md5(String input) throws Exception {
    MessageDigest md5 = MessageDigest.getInstance("MD5");
    md5.update(input.getBytes("UTF-8"));
    BigInteger hash = new BigInteger(1, md5.digest());
    return String.format("%1$032X", hash);
}

From source file:Main.java

public static String toBase58(byte[] b) {
    if (b.length == 0) {
        return "";
    }/*w  ww.ja v  a  2s  .  co m*/

    int lz = 0;
    while (lz < b.length && b[lz] == 0) {
        ++lz;
    }

    StringBuffer s = new StringBuffer();
    BigInteger n = new BigInteger(1, b);
    while (n.compareTo(BigInteger.ZERO) > 0) {
        BigInteger[] r = n.divideAndRemainder(BigInteger.valueOf(58));
        n = r[0];
        char digit = b58[r[1].intValue()];
        s.append(digit);
    }
    while (lz > 0) {
        --lz;
        s.append("1");
    }
    return s.reverse().toString();
}

From source file:Main.java

public static PublicKey pubKeyFromJwk(String jwkp) {
    PublicKey pubKey = null;/*from w  ww .j  ava  2  s. co m*/

    try {
        JSONObject jk = new JSONObject(jwkp).getJSONArray("keys").getJSONObject(0);

        BigInteger n = new BigInteger(1, decodeB64(jk.getString("n")));
        BigInteger e = new BigInteger(1, decodeB64(jk.getString("e")));
        RSAPublicKeySpec pubRsaSpec = new RSAPublicKeySpec(n, e);
        KeyFactory keyfact = KeyFactory.getInstance("RSA", "SC");
        pubKey = keyfact.generatePublic(pubRsaSpec);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return pubKey;
}

From source file:Main.java

private static String md5(String origin) {
    try {/*from  w  w w .  jav  a 2s  .  c om*/
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(origin.getBytes("UTF-8"));
        BigInteger bi = new BigInteger(1, md.digest());

        return bi.toString(16);
    } catch (Exception e) {
        return getUuid();
    }
}

From source file:Main.java

public static String getMD5Hash(String s) throws NoSuchAlgorithmException {
    MessageDigest m = MessageDigest.getInstance("MD5");
    byte[] data = s.getBytes();
    m.update(data, 0, data.length);/*  w  w w  .  j a  v  a 2 s.c  o  m*/
    BigInteger i = new BigInteger(1, m.digest());
    return String.format("%1$032X", i);
}