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.sample.TimeController.java

@RequestMapping(method = RequestMethod.GET, value = { "/tick" })
public ModelAndView get() throws Exception {
    Connection connection = jmsFactory.createConnection();
    Session jmsSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    SecureRandom srandom = new SecureRandom();
    String rand = new BigInteger(176, srandom).toString(32);
    String q = Long.toString(System.currentTimeMillis()) + "-" + rand;
    Destination destination = jmsSession.createQueue(q);

    Timer timer = new Timer();
    long delay = 1 * 1000;
    timer.schedule(new TickTask(jmsSession, destination), 0, delay);

    ModelAndView mav = new ModelAndView("client");
    mav.addObject("queue", destination.toString());
    return mav;/*  w w  w .  j av  a 2 s . c  o  m*/
}

From source file:de.uniwue.info6.misc.StringTools.java

/**
 *
 *
 * @return/*ww w .  j  a va2  s.  com*/
 */
public static String generatePassword(int numBits, int length) {
    return new BigInteger(numBits, random).toString(length);
}

From source file:org.berlin_vegan.bvapp.acra.ACRAPostSender.java

private static String md5(String s) {
    MessageDigest m = null;//from  w ww.  ja v a  2  s  .  co m
    try {
        m = MessageDigest.getInstance("MD5");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    m.update(s.getBytes(), 0, s.length());
    return new BigInteger(1, m.digest()).toString(16);
}

From source file:com.whynot.checkOtrade.web.ws.LoginController.java

/**
 *     ?, ?  /*from w  w  w . j  a  v  a 2s .c  o  m*/
 * ?? ?? - ? 
 *  ?     -,
 *  ?  .
 * @param data
 * @return
 */
@RequestMapping(value = "rest/login", method = RequestMethod.POST)
public @ResponseBody String login(LoginData data) {
    String response = "null";
    System.out.println(data.getLogin() + " :: " + data.getPassword());
    Account acc = us.findByEmail(data.getLogin());
    System.out.println("acc :: " + acc);
    if (acc == null) {
        return response;
    }
    System.out.println("acc :: " + acc);
    if (acc.getPassword().equals(data.getPassword())) {
        SecureRandom random = new SecureRandom();
        response = new BigInteger(130, random).toString(32);
    }
    usermap.put(response, acc);
    return response;
}

From source file:eu.mondo.driver.mongo.util.MStatementDeserializer.java

@Override
public MStatement deserialize(JsonParser jp, DeserializationContext ctxt)
        throws IOException, JsonProcessingException {

    String objectString = null;// ww  w. j ava 2s .c  o m
    String predicateString = null;
    String subjectString = null;

    BigInteger subjectBI;
    BigInteger predicateBI;
    BigInteger objectBI;

    ObjectMapper mapper = new ObjectMapper();
    JsonNode root = mapper.readTree(jp);

    subjectString = root.path("subject").textValue();
    predicateString = root.path("predicate").textValue();
    objectString = root.path("object").textValue();

    String subjectBIS = root.path("subjectBI").textValue();
    String predicateBIS = root.path("predicateBI").textValue();
    String objectBIS = root.path("objectBI").textValue();
    subjectBI = "".equals(subjectBIS) || subjectBIS == null ? new BigInteger("0", 10)
            : new BigInteger(subjectBIS, 16);
    predicateBI = "".equals(predicateBIS) || predicateBIS == null ? new BigInteger("0", 10)
            : new BigInteger(predicateBIS, 16);
    objectBI = "".equals(objectBIS) || objectBIS == null ? new BigInteger("0", 10)
            : new BigInteger(objectBIS, 16);

    //        URI subject = new URIImpl(subjectString);
    //        URI predicate = new URIImpl(predicateString);
    //
    //        Value object;
    //        try {
    //            object = new URIImpl(objectString);
    //        } catch (Exception e) {
    //            object = ValueFactoryImpl.getInstance().createLiteral(objectString);
    //        }

    jp.close();

    MStatement statement = new MStatement();
    statement.setSubject(subjectString);
    statement.setPredicate(predicateString);
    statement.setObject(objectString);
    statement.setSubjectBI(subjectBI);
    statement.setPredicateBI(predicateBI);
    statement.setObjectBI(objectBI);

    return statement;
}

From source file:datafu.pig.hash.MD5.java

public String call(String val) {
    if (isBase64) {
        return new String(Base64.encodeBase64(md5er.digest(val.getBytes())));
    } else {/*from w w  w .  j av  a2s . c  o  m*/
        return String.format("%032x", new BigInteger(1, md5er.digest(val.getBytes())));
    }
}

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

public static String md5(String input) {

    String md5 = null;//  w w w . j  av  a 2s  .  com

    if (null == input)
        return null;

    try {

        //Create MessageDigest object for MD5
        MessageDigest digest = MessageDigest.getInstance("MD5");

        //Update input string in message digest
        digest.update(input.getBytes(), 0, input.length());

        //Converts message digest value in base 16 (hex)
        md5 = new BigInteger(1, digest.digest()).toString(16);

    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return md5;
}

From source file:controllers.impl.StandardAuthentication.java

@Override
public F.Promise<Result> auth(final String redirectUrl) {
    final Configuration config = Configuration.root();
    final String baseURL = config.getString("auth.ghe.baseURL");
    final String clientId = config.getString("auth.ghe.clientId");

    final String state = new BigInteger(160, RANDOM).toString(32);
    // TODO(barp): This should go in the database or memcached
    URL_CACHE.put(state, redirectUrl);

    final URI uri;
    try {/*w w w . j a  v  a2  s .co  m*/
        uri = apiUriBuilder(baseURL, "/login/oauth/authorize").addParameter("client_id", clientId)
                .addParameter("scope", "user:email,read:org").addParameter("state", state).build();
    } catch (final URISyntaxException e) {
        LOGGER.error("Unable to build URI for GHE authentication", e);
        return F.Promise.pure(internalServerError());
    }

    LOGGER.info("Redirecting login to " + uri.toString());

    return F.Promise.pure(redirect(uri.toString()));
}

From source file:com.github.sshw.controller.TerminalController.java

public String nextKey() {
    return new BigInteger(130, random).toString(32);
}

From source file:com.amazonaws.kinesis.agg.AggRecordTest.java

@Test
public void shouldGenerateValidHashKeys() {
    final String expectedHashKeyHex = DigestUtils.md5Hex(partitionKey);
    final String expectedHashKeyDecimal = new BigInteger(expectedHashKeyHex, 16).toString(10);

    final AggRecord record = new AggRecord();
    record.addUserRecord(partitionKey, null, "dummy data".getBytes());

    Assert.assertThat(new BigInteger(expectedHashKeyDecimal).compareTo(MIN_VALID_HASHKEY) >= 0, is(true));

    Assert.assertThat(new BigInteger(expectedHashKeyDecimal).compareTo(MAX_VALID_HASHKEY) <= 0, is(true));

    Assert.assertThat(record.getExplicitHashKey(), equalTo(expectedHashKeyDecimal));
}