Package java.math

Examples of java.math.BigInteger.toByteArray()


    }
   
    private static class BigIntegerColumnSerializer extends ColumnSerializer {
        protected void writeObject(ObjectOutput out, Object obj) throws IOException {
            BigInteger val = (BigInteger)obj;
            byte[] bytes = val.toByteArray();
            out.writeInt(bytes.length);
            out.write(bytes);
        }
        protected Object readObject(ObjectInput in) throws IOException {
            int length = in.readInt();
View Full Code Here


    private static class BigDecimalColumnSerializer extends ColumnSerializer {
        protected void writeObject(ObjectOutput out, Object obj) throws IOException {
            BigDecimal val = (BigDecimal)obj;
            out.writeInt(val.scale());
            BigInteger unscaled = val.unscaledValue();
            byte[] bytes = unscaled.toByteArray();
            out.writeInt(bytes.length);
            out.write(bytes);
        }
        protected Object readObject(ObjectInput in) throws IOException {
            int scale = in.readInt();
View Full Code Here

        BigInteger  z = agree.calculateAgreement(pubParam);

        if (forEncryption)
        {
            return encryptBlock(in, inOff, inLen, z.toByteArray());
        }
        else
        {
            return decryptBlock(in, inOff, inLen, z.toByteArray());
        }
View Full Code Here

        {
            return encryptBlock(in, inOff, inLen, z.toByteArray());
        }
        else
        {
            return decryptBlock(in, inOff, inLen, z.toByteArray());
        }
    }
}
View Full Code Here

                        writeVarLong(b.longValue());
                    }
                } else {
                    writeByte((byte) type);
                    writeVarInt(scale);
                    byte[] bytes = b.toByteArray();
                    writeVarInt(bytes.length);
                    write(bytes, 0, bytes.length);
                }
            }
            break;
View Full Code Here

                if (scale == 0) {
                    return 1 + getVarLongLen(b.longValue());
                }
                return 1 + getVarIntLen(scale) + getVarLongLen(b.longValue());
            }
            byte[] bytes = b.toByteArray();
            return 1 + getVarIntLen(scale) + getVarIntLen(bytes.length) + bytes.length;
        }
        case Value.TIME:
            if (SysProperties.STORE_LOCAL_TIME) {
                long nanos = ((ValueTime) v).getNanos();
View Full Code Here

    @Test
    public void testToHex() {
        assertNull("Null uuid", ByteUtils.toHex(null));
        BigInteger x = new BigInteger("11");
        assertEquals("11 converts to 0b", "0b", ByteUtils.toHex(x.toByteArray()));
        x = new BigInteger("91341076760875801477766333660764240022");
        assertEquals("Number has been converted", "44b7a6c7f58a5dcdf1594ad7003af896", ByteUtils.toHex(x.toByteArray()));
        byte[] hex = StringUtils.encodeHex("44b7a6c7f58a5dcdf1594ad7003af896");
        assertEquals("An hex array is not recoded", "44b7a6c7f58a5dcdf1594ad7003af896", ByteUtils.toHex(hex));
    }
View Full Code Here

    public void testToHex() {
        assertNull("Null uuid", ByteUtils.toHex(null));
        BigInteger x = new BigInteger("11");
        assertEquals("11 converts to 0b", "0b", ByteUtils.toHex(x.toByteArray()));
        x = new BigInteger("91341076760875801477766333660764240022");
        assertEquals("Number has been converted", "44b7a6c7f58a5dcdf1594ad7003af896", ByteUtils.toHex(x.toByteArray()));
        byte[] hex = StringUtils.encodeHex("44b7a6c7f58a5dcdf1594ad7003af896");
        assertEquals("An hex array is not recoded", "44b7a6c7f58a5dcdf1594ad7003af896", ByteUtils.toHex(hex));
    }

    @Test
View Full Code Here

        assertNull(StringUtils.encodeHex(null));
        BigInteger x = new BigInteger("10");
        String uuid = "3b0ae7d419d26e36e040007f0101785c";
        assertEquals("RAW 16", 16, StringUtils.encodeHex(uuid).length);
        assertEquals("RAW 16", uuid, ByteUtils.toHex(StringUtils.encodeHex(uuid)));
        assertTrue("Number has been converted", 10 == StringUtils.encodeHex(ByteUtils.toHex(x.toByteArray()))[0]);
        String enc = "QCcyTE4v9EgCGo+kPGeI6LZ5XK0+3JLa7dC90DwKabHd9gtBd+/pJg==";
        byte[] encbytes = enc.getBytes();
        assertEquals("Encrypted data is treated ok", enc, new String(StringUtils.encodeHex(enc)));
        assertEquals("Encrypted data is treated ok", encbytes.length, StringUtils.encodeHex(ByteUtils.toHex(encbytes)).length);
        assertEquals("Encrypted data is treated ok", encbytes[0], StringUtils.encodeHex(ByteUtils.toHex(encbytes))[0]);
View Full Code Here

    {
      byte[] kbytes = "jaas is the way".getBytes();
      SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
 
      BigInteger n = new BigInteger(secret, 16);
      byte[] encoding = n.toByteArray();
     
      Cipher cipher = Cipher.getInstance("Blowfish");
      cipher.init(Cipher.DECRYPT_MODE, key);
      byte[] decode = cipher.doFinal(encoding);
      return new String(decode);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.