de.cscc.crypto.util
Class BigIntegerUtil

java.lang.Object
  extended byde.cscc.crypto.util.BigIntegerUtil

public final class BigIntegerUtil
extends Object

BigIntegerUtil Class.

This is a wrapper class for frequentliy used methods that are missed in the BigInteger class. Because BigInteger is immutable we are not able to extend this class.

Version:
$Revision: 1.2 $
Author:
Uwe Günther

Method Summary
static byte[] toUnsignedByteArray(BigInteger signature)
          Cuts a leading 0x00 byte that indicates that this number is non negative.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toUnsignedByteArray

public static byte[] toUnsignedByteArray(BigInteger signature)
Cuts a leading 0x00 byte that indicates that this number is non negative.

BigInterger#toByteArray returns a two's-complement representation of the BigInteger. This does not matter because we hav a non negative number (number >= 0). Two's Complement uses the leftmost bit (most significant bit) for the sign bit. Because BigInteger represents infinite numbers, there is no concrete sign bit. This isn't realy a problem for us, because positive numbers has no sign bit. But what, if a positive number where the leftmost bit in its leftmost byte is set? Is it a negative or a positive number? For these cases BigInteger#toByteArray adds a whole 0x00 byte add the left side to indicate this number is positive. This byte is bad for us, so we want to filter it out in this method.

Parameters:
signature - the signature that will be converted to an unsigned byte[].
Throws:
NullPointerException - if signature is null.
IllegalArgumentException - if signature is a negative number.
See Also:
BigInteger.toByteArray()


Copyright © 2001, 2002 by Uwe Günther. See the COPYING file for more details. Browse the source as HTML.