Package java.math

Examples of java.math.BigInteger.toByteArray()


                s += 8;

                BigDecimal bigdecimal = (BigDecimal) o;
                BigInteger bigint     = JavaSystem.unscaledValue(bigdecimal);

                s += bigint.toByteArray().length;
                break;

            case Types.SQL_BOOLEAN :
                s += 1;
                break;
View Full Code Here


   * @return public key
   */
  protected static byte[] getPublicKey(KeyPair keyPair) {
     DHPublicKey incomingPublicKey = (DHPublicKey) keyPair.getPublic();
     BigInteger  dhY = incomingPublicKey.getY();
     byte[] result = dhY.toByteArray();
     byte[] temp = new byte[KEY_LENGTH];
     if (result.length < KEY_LENGTH) {
       System.arraycopy(result, 0, temp, KEY_LENGTH - result.length, result.length);
       result = temp;
     } else if(result.length > KEY_LENGTH){
View Full Code Here

            idArray = new COSArray();
            try
            {
                MessageDigest md = MessageDigest.getInstance( "MD5" );
                BigInteger time = BigInteger.valueOf( System.currentTimeMillis() );
                md.update( time.toByteArray() );
                md.update( ownerPassword.getBytes() );
                md.update( userPassword.getBytes() );
                md.update( document.getDocument().toString().getBytes() );
                byte[] id = md.digest( this.toString().getBytes() );
                COSString idString = new COSString();
View Full Code Here

            idArray = new COSArray();
            try
            {
                MessageDigest md = MessageDigest.getInstance( "MD5" );
                BigInteger time = BigInteger.valueOf( System.currentTimeMillis() );
                md.update( time.toByteArray() );
                md.update( ownerPassword.getBytes() );
                md.update( userPassword.getBytes() );
                md.update( document.toString().getBytes() );
                byte[] id = md.digest( this.toString().getBytes() );
                COSString idString = new COSString();
View Full Code Here

        output.write(bignum.value.signum() >= 0 ? '+' : '-');
       
        BigInteger absValue = bignum.value.abs();
       
        byte[] digits = absValue.toByteArray();
       
        boolean oddLengthNonzeroStart = (digits.length % 2 != 0 && digits[0] != 0);
        int shortLength = digits.length / 2;
        if (oddLengthNonzeroStart) {
            shortLength++;
View Full Code Here

                    BigInteger bigInt = new BigInteger(stringVal);
                   
                    // we don't deal with negatives.
                    if (bigInt.compareTo(BigInteger.ZERO) >= 0) {
                        int bitLength = bigInt.toString(2).length();
                        byte[] bytes = bigInt.toByteArray();
                       
                        byte[] buf = new byte[(bitLength / 7) + ((bitLength % 7) > 0 ? 1 : 0)];

                        int b = 0;
                        int destBit = 0;
View Full Code Here

        if (sign || base == 10 || val.signum() >= 0) {
            return stringToBytes(val.toString(base),upper);
        }

        // negative values
        byte[] bytes = val.toByteArray();
        switch(base) {
        case 2return Convert.twosComplementToBinaryBytes(bytes);
        case 8return Convert.twosComplementToOctalBytes(bytes);
        case 16: return Convert.twosComplementToHexBytes(bytes,upper);
        default: return stringToBytes(val.toString(base),upper);
View Full Code Here

        i++;
        if (i == 0) return a;
        if (i == num + 1) return b;

        BigInteger curBI = startBI.add(intervalBI.multiply(BigInteger.valueOf(i)));
        byte [] padded = curBI.toByteArray();
        if (padded[1] == 0)
          padded = tail(padded, padded.length - 2);
        else
          padded = tail(padded, padded.length - 1);
        return padded;
View Full Code Here

                if (log.isDebugEnabled()) {
                    log.debug("BigInteger 16 encoding on output ");
                }

                BigInteger n = new BigInteger(IOUtils.toString(inputStream), 16);
                decodedInputStream = new ByteArrayInputStream(n.toByteArray());
                break;
            default:
                throw new IllegalArgumentException("Unsupported encoding type");
        }
View Full Code Here

            imageID = (BigInteger)((PlanarImage)owner).getImageID();
        else if (owner instanceof SerializableRenderedImage)
            imageID = (BigInteger)((SerializableRenderedImage)owner).getImageID();

        if (imageID != null) {
            byte[] buf = imageID.toByteArray();
            int length = buf.length;
            byte[] buf1 = new byte[length + 8];
            System.arraycopy(buf, 0, buf1, 0, length);
            for (int i = 7, j = 0; i >= 0; i--, j += 8)
                buf1[length++] = (byte)(idx >> j);
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.