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(long val) 

Source Link

Document

Constructs a BigInteger with the specified value, which may not be zero.

Usage

From source file:com.redhat.lightblue.crud.validator.MinMaxCheckerTest.java

/**
 * Col1: For debugging purposes to know which test case had issues
 * Col2: A instantiation to test with. Should always represent 2.
 *//*  ww w  . j  a  v a2 s .  c om*/
@Parameters(name = "{index}: {0}")
public static Collection<Object[]> data() {
    return Arrays.asList(new Object[][] { { Integer.class, new Integer(2) },
            { Byte.class, new Byte(new Integer(2).byteValue()) },
            { Short.class, new Short(new Integer(2).shortValue()) }, { Long.class, new Long(2L) },
            { Float.class, new Float(2F) }, { Double.class, new Double(2D) },
            { BigInteger.class, new BigInteger("2") }, { BigDecimal.class, new BigDecimal(2) } });
}

From source file:CryptPassword.java

/**
 * @param username// www  .ja v a2 s .c om
 * @param realm
 * @param md5Password
 * @return is the Digest password valid with the given real
 */
public static boolean isMD5DigestValid(String username, String realm, String md5Password) {
    byte b[];
    try {
        b = MessageDigest.getInstance("MD5").digest((username + ":" + realm + ":" + md5Password).getBytes());
    } catch (NoSuchAlgorithmException e) {
        return false;
    }
    BigInteger bi = new BigInteger(b);
    String s = bi.toString(16);
    if (s.length() % 2 != 0) {
        s = "0" + s; // String s is the encrypted password
    }
    return s.equals(md5Password);
}

From source file:MainClass.java

public void run() {

    ByteBuffer sizeb = ByteBuffer.allocate(4);
    try {/*from  w  w w . j a v  a  2s  . c o  m*/
        while (sizeb.hasRemaining())
            in.read(sizeb);
        sizeb.flip();
        int howMany = sizeb.getInt();
        sizeb.clear();

        for (int i = 0; i < howMany; i++) {
            while (sizeb.hasRemaining())
                in.read(sizeb);
            sizeb.flip();
            int length = sizeb.getInt();
            sizeb.clear();

            ByteBuffer data = ByteBuffer.allocate(length);
            while (data.hasRemaining())
                in.read(data);

            BigInteger result = new BigInteger(data.array());
            System.out.println(result);
        }
    } catch (IOException ex) {
        System.err.println(ex);
    } finally {
        try {
            in.close();
        } catch (Exception ex) {
            // We tried
        }
    }
}

From source file:jp.co.ntts.vhut.util.MacConversionUtil.java

/**
 * ?????????.//  w w w  .  ja v  a2  s.co  m
 * @param macStart .
 * @param count ?
 * @return 
 */
public static byte[] getMacAddressWithOrderAsByte(String macStart, int count) {
    BigInteger biMacStart = new BigInteger(addrToByte(macStart));
    BigInteger biSub = BigInteger.valueOf(count);
    byte[] bMacTarget = biMacStart.add(biSub).toByteArray();
    byte[] result = new byte[6];
    int delta = 6 - bMacTarget.length;
    for (int i = 0; i < 6; i++) {
        if (i >= delta) {
            result[i] = bMacTarget[i - delta];
        } else {
            result[i] = (byte) 0;
        }
    }
    return result;
}

From source file:cherry.foundation.type.SecureBigIntegerTest.java

@Test
public void testRandomTest() {
    for (int i = 0; i < 100; i++) {
        BigInteger plain = new BigInteger(RandomUtils.nextBytes(1024));
        SecureBigInteger sec0 = plainValueOf(plain);
        SecureBigInteger sec1 = cryptoValueOf(sec0.crypto());
        assertThat(sec1.plain(), is(plain));
    }//from w  w  w  .ja  v a2s.c om
}

From source file:com.coroptis.coidi.core.services.impl.ConvertorServiceImpl.java

@Override
public BigInteger convertToBigIntegerFromString(String s) {
    return new BigInteger(convertToBytes(s));
}

From source file:com.forsrc.utils.MyRsaUtils.java

/**
 * Decrypt string./* ww w  .j a  v a2s .  c  o  m*/
 *
 * @param rsaKey    the rsa key
 * @param encrypted the encrypted
 * @return the string
 * @throws IOException the io exception
 */
public static String decrypt(RsaKey rsaKey, String encrypted) throws IOException {
    BigInteger encrypt = new BigInteger(new String(new Base64().decode(encrypted)));
    return bigInteger2String(decrypt(rsaKey, encrypt));
}

From source file:RSA.java

/** Decrypt the given ciphertext message. */
public synchronized String decrypt(String message) {
    return new String((new BigInteger(message)).modPow(d, n).toByteArray());
}

From source file:cl.niclabs.tscrypto.common.datatypes.BigIntegerBase64TypeAdapter.java

@Override
public BigInteger deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
        throws JsonParseException {
    return new BigInteger(Base64.decodeBase64(json.getAsString()));
}

From source file:cherry.foundation.type.SecureBigDecimalTest.java

@Test
public void testRandomTest() {
    for (int i = 0; i < 100; i++) {
        BigInteger bi = new BigInteger(RandomUtils.nextBytes(1024));
        int scale = random.nextInt();
        BigDecimal plain = new BigDecimal(bi, scale);
        SecureBigDecimal sec0 = plainValueOf(plain);
        SecureBigDecimal sec1 = cryptoValueOf(sec0.crypto());
        assertThat(sec1.plain(), is(plain));
    }//from   w w w  . j a v a 2  s .  c o m
}