Example usage for java.math BigInteger toByteArray

List of usage examples for java.math BigInteger toByteArray

Introduction

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

Prototype

public byte[] toByteArray() 

Source Link

Document

Returns a byte array containing the two's-complement representation of this BigInteger.

Usage

From source file:co.rsk.blockchain.utils.BlockGenerator.java

public static Block createBlock(int number, int ntxs) {
    Bloom logBloom = new Bloom();
    Block parent = BlockGenerator.getGenesisBlock();

    List<Transaction> txs = new ArrayList<>();

    for (int ntx = 0; ntx < ntxs; ntx++)
        txs.add(new SimpleRskTransaction(null));

    byte[] parentMGP = (parent.getMinimumGasPrice() != null) ? parent.getMinimumGasPrice()
            : BigInteger.valueOf(10L).toByteArray();
    BigInteger minimumGasPrice = new MinimumGasPriceCalculator().calculate(new BigInteger(1, parentMGP),
            BigInteger.valueOf(100L));

    return new Block(parent.getHash(), // parent hash
            EMPTY_LIST_HASH, // uncle hash
            parent.getCoinbase(), // coinbase
            logBloom.getData(), // logs bloom
            parent.getDifficulty(), // difficulty
            number, parent.getGasLimit(), parent.getGasUsed(), parent.getTimestamp() + ++count,
            EMPTY_BYTE_ARRAY, // extraData
            EMPTY_BYTE_ARRAY, // mixHash
            BigInteger.ZERO.toByteArray(), // provisory nonce
            EMPTY_TRIE_HASH, // receipts root
            EMPTY_TRIE_HASH, // transaction receipts
            EMPTY_TRIE_HASH, // state root
            txs, // transaction list
            null, // uncle list
            minimumGasPrice.toByteArray());
}

From source file:edu.illinois.ncsa.domain.FileDescriptor.java

/**
 * @param md5sum/*from  w w  w . j av  a  2  s .co  m*/
 *            the md5sum to set
 */
@JsonIgnore
public void setMd5sum(BigInteger md5sum) {
    if (md5sum.signum() < 0) {
        md5sum = new BigInteger(1, md5sum.toByteArray());
    }
    this.md5sum = md5sum.toString(16);
    if (this.md5sum.length() < 16) {
        this.md5sum = "00000000000000000000000000000000".substring(this.md5sum.length()) + this.md5sum;
    }
}

From source file:mx.bigdata.sat.cfdi.TFDv1.java

private TimbreFiscalDigital createStamp(UUID uuid, Date date) {
    ObjectFactory of = new ObjectFactory();
    TimbreFiscalDigital tfd = of.createTimbreFiscalDigital();
    tfd.setVersion("1.0");
    tfd.setFechaTimbrado(date);//from w w  w  .j a va2s. c om
    tfd.setSelloCFD(document.getSello());
    tfd.setUUID(uuid.toString());
    BigInteger bi = cert.getSerialNumber();
    tfd.setNoCertificadoSAT(new String(bi.toByteArray()));
    return tfd;
}

From source file:com.coroptis.coidi.core.message.AbstractMessage.java

public String convertToString(final BigInteger b) {
    return convertToString(b.toByteArray());
}

From source file:mx.bigdata.sat.cfdi.TFDv11.java

private TimbreFiscalDigital createStamp(UUID uuid, Date date, String PAC, String leyenda)
        throws DatatypeConfigurationException {
    ObjectFactory of = new ObjectFactory();
    TimbreFiscalDigital tfds = of.createTimbreFiscalDigital();
    tfds.setVersion("1.1");
    tfds.setUUID(uuid.toString());//  ww w.ja  v a2  s. co  m
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    tfds.setFechaTimbrado(DatatypeFactory.newInstance().newXMLGregorianCalendar(c.get(Calendar.YEAR),
            c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), c.get(Calendar.HOUR_OF_DAY),
            c.get(Calendar.MINUTE), c.get(Calendar.SECOND), DatatypeConstants.FIELD_UNDEFINED,
            DatatypeConstants.FIELD_UNDEFINED));
    tfds.setRfcProvCertif(PAC);
    tfds.setLeyenda(leyenda);
    tfds.setSelloCFD(document.getSello());
    BigInteger bi = cert.getSerialNumber();
    tfds.setNoCertificadoSAT(new String(bi.toByteArray()));
    return tfds;
}

From source file:org.apache.spark.network.crypto.AuthEngine.java

@VisibleForTesting
byte[] rawResponse(byte[] challenge) {
    BigInteger orig = new BigInteger(challenge);
    BigInteger response = orig.add(ONE);
    return response.toByteArray();
}

From source file:mx.bigdata.sat.cfdi.TFDv11c33.java

private TimbreFiscalDigital createStamp(UUID uuid, Date date, String PAC, String leyenda)
        throws DatatypeConfigurationException {
    Calendar c = Calendar.getInstance();
    c.setTime(date);//from   w w  w  .jav a  2  s . c  om
    ObjectFactory of = new ObjectFactory();
    TimbreFiscalDigital tfds = of.createTimbreFiscalDigital();
    tfds.setVersion("1.1");
    tfds.setUUID(uuid.toString());
    tfds.setFechaTimbrado(DatatypeFactory.newInstance().newXMLGregorianCalendar(c.get(Calendar.YEAR),
            c.get(Calendar.MONTH), c.get(Calendar.DATE), c.get(Calendar.HOUR), c.get(Calendar.MINUTE),
            c.get(Calendar.SECOND), DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED));
    tfds.setRfcProvCertif(PAC);
    tfds.setLeyenda(leyenda);
    tfds.setSelloCFD(document.getSello());
    BigInteger bi = cert.getSerialNumber();
    tfds.setNoCertificadoSAT(new String(bi.toByteArray()));
    return tfds;
}

From source file:org.mitre.openid.connect.view.JwkKeyListView.java

@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {

        public boolean shouldSkipField(FieldAttributes f) {

            return false;
        }//  w w w. ja  v a 2 s.c  o  m

        public boolean shouldSkipClass(Class<?> clazz) {
            // skip the JPA binding wrapper
            if (clazz.equals(BeanPropertyBindingResult.class)) {
                return true;
            }
            return false;
        }

    }).create();

    response.setContentType("application/json");

    Writer out = response.getWriter();

    //BiMap<String, PublicKey> keyMap = (BiMap<String, PublicKey>) model.get("keys");
    Map<String, JwtSigner> signers = (Map<String, JwtSigner>) model.get("signers");

    JsonObject obj = new JsonObject();
    JsonArray keys = new JsonArray();
    obj.add("keys", keys);

    for (String keyId : signers.keySet()) {

        JwtSigner src = signers.get(keyId);

        if (src instanceof RsaSigner) {

            RsaSigner rsaSigner = (RsaSigner) src;

            RSAPublicKey rsa = (RSAPublicKey) rsaSigner.getPublicKey(); // we're sure this is an RSAPublicKey b/c this is an RsaSigner

            BigInteger mod = rsa.getModulus();
            BigInteger exp = rsa.getPublicExponent();

            String m64 = Base64.encodeBase64URLSafeString(mod.toByteArray());
            String e64 = Base64.encodeBase64URLSafeString(exp.toByteArray());

            JsonObject o = new JsonObject();

            o.addProperty("use", "sig"); // since we don't do encryption yet
            o.addProperty("alg", "RSA"); //rsaSigner.getAlgorithm()); // we know this is RSA
            o.addProperty("mod", m64);
            o.addProperty("exp", e64);
            o.addProperty("kid", keyId);

            keys.add(o);
        } // TODO: deal with non-RSA key types
    }

    gson.toJson(obj, out);

}

From source file:org.rifidi.edge.core.services.notification.data.EPCGeneration2Event.java

@Override
public void setEPCMemory(BigInteger memBank, Integer length) {
    hex = new String(Hex.encodeHex(memBank.toByteArray()));
    memoryBanks.get(1).setMemory(memBank);
    memoryBanks.get(1).setLength(length);
}

From source file:nl.salp.warcraft4j.hash.Lookup2Hash.java

@Override
public byte[] hash(byte[] data) {
    BigInteger hash = BigInteger.valueOf(jenkinsHash(data));
    return DataTypeUtil.trim(hash.toByteArray());

}