net.rim.device.api.crypto
Class CryptoInteger

java.lang.Object
  extended by net.rim.device.api.crypto.CryptoInteger

public class CryptoInteger
extends Object

Represents large unsigned integer arithmetic class.

Most operations are performed with respect to a modulus.

Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

Constructor Summary
Category: Signed protected CryptoInteger()
          Deprecated. If you use this constructor, all of the public functions in this class may throw NullPointerExceptions. Instead use the public constructors.
Category: Signed   CryptoInteger(byte[] value)
          Constructs a CryptoInteger object with the given byte array.
Category: Signed   CryptoInteger(byte[] value, int offset, int length)
          Constructs a CryptoInteger object with the given byte array.
Category: Signed   CryptoInteger(int value)
          Creates a CryptoInteger object with the given integer parameter.
Category: Signed   CryptoInteger(String value)
          Constructs a CryptoInteger object with the given hexadecimal string.
Category: Signed   CryptoInteger(CryptoInteger other)
          Creates a copy of a given CryptoInteger instance.
 
Method Summary
Category: Signed  CryptoInteger add(CryptoInteger a, CryptoInteger modulus)
          Returns a CryptoInteger whose value is (this + a) mod modulus.
Category: Signed  int compareTo(int other)
          Compares this CryptoInteger with the specified integer value.
Category: Signed  int compareTo(CryptoInteger other)
          Compares this CryptoInteger with the specified CryptoInteger.
Category: Signed  void decrement(int a, CryptoInteger modulus)
          Decrements this CryptoInteger by a, all modulo modulus.
Category: Signed  void decrement(CryptoInteger a, CryptoInteger modulus)
          Decrements this CryptoInteger by a, all modulo modulus.
Category: Signed  void divideByTwo(CryptoInteger modulus)
          Divides this by two modulo modulus. i.e. the resulting value * 2 will be equivalent to this mod modulus.
Category: Signed  boolean equals(Object obj)
          Indicates whether some other object is "equal to" this one.
Category: Signed  CryptoInteger exponent(CryptoInteger exponent, CryptoInteger modulus)
          Returns a CryptoInteger whose value is thisexponent mod modulus.
Category: Signed  CryptoInteger gcd(CryptoInteger a)
          Returns the greatest common denominator of this and a.
Category: Signed  int hashCode()
          Returns a hash code value for the object.
Category: Signed  void increment(int a, CryptoInteger modulus)
          Increments this CryptoInteger by a, all modulo modulus.
Category: Signed  void increment(CryptoInteger a, CryptoInteger modulus)
          Increments this CryptoInteger by a, all modulo modulus.
Category: Signed  CryptoInteger invert(CryptoInteger modulus)
          Returns the inverse of this modulo modulus.
Category: Signed  boolean isOdd()
          Determines if this CryptoInteger is odd.
Category: Signed  CryptoInteger mod(CryptoInteger modulus)
          Returns a CryptoInteger whose value is this mod modulus.
Category: Signed  CryptoInteger multiply(CryptoInteger a, CryptoInteger modulus)
          Returns a CryptoInteger whose value is (this * a) mod modulus.
Category: Signed  void multiplyByTwo(CryptoInteger modulus)
          Multiplies this by two, modulo modulus.
Category: Signed  CryptoInteger square(CryptoInteger modulus)
          Returns a CryptoInteger whose value is this2 mod modulus.
Category: Signed  CryptoInteger subtract(CryptoInteger a, CryptoInteger modulus)
          Returns a CryptoInteger whose value is (this - a) mod modulus.
Category: Signed  byte[] toByteArray()
          Returns the byte array representation of the value.
Category: Signed  byte[] toByteArray(int length)
          Returns the byte array representation of the value, padded or truncated to the specified length.
Category: Signed  String toString()
          Returns the hexadecimal string representation of the value.
Category: Signed  String toString(int numberOfBytes)
          Returns the hexadecimal string representation of the value, padded or truncated to the specified number of bytes (the string length will be twice this number).
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 



Constructor Detail

CryptoInteger

public CryptoInteger(int value)
Creates a CryptoInteger object with the given integer parameter.

Note: This object is mutable, and therefore so is the hash code. Don't modify this object after you place it in a hashtable.

Parameters:
value - The integer representation of the non-negative value.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CryptoInteger

public CryptoInteger(byte[] value)
Constructs a CryptoInteger object with the given byte array.

The first byte in the array is considered the most significant. The length of the given byte array must be in the range 1-256.

Note: This object is mutable, and therefore so is the hash code. Don't modify this object after you place it in a hashtable.

Parameters:
value - The byte array representation of the value.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CryptoInteger

public CryptoInteger(byte[] value,
                     int offset,
                     int length)
Constructs a CryptoInteger object with the given byte array.

The first byte in the array is considered most significant.

Note: This object is mutable, and therefore so is the hash code. Don't modify this object after you place it in a hashtable.

Parameters:
value - The byte array representation of the value.
offset - The starting offset of the data to use from value.
length - The number of bytes to use. Must be in the range 1-256.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CryptoInteger

public CryptoInteger(String value)
Constructs a CryptoInteger object with the given hexadecimal string.

Characters must be 0-9, A-F, or a-f. The first character in the string is considered most significant. The string must represent 1 to 256 full bytes, i.e. 2 characters per byte.

Note: This object is mutable, and therefore so is the hash code. Don't modify this object after you place it in a hashtable.

Parameters:
value - The hexadecimal string representation of the value.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CryptoInteger

public CryptoInteger(CryptoInteger other)
Creates a copy of a given CryptoInteger instance.

Note: This object is mutable, and therefore so is the hash code. Don't modify this object after you place it in a hashtable.

Parameters:
other - The CryptoInteger object to be copied.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

CryptoInteger

protected CryptoInteger()
Deprecated. If you use this constructor, all of the public functions in this class may throw NullPointerExceptions. Instead use the public constructors.

Creates a CryptoInteger object.

This is the default constructor.

Note: This object is mutable, and therefore so is the hash code. Don't modify this object after you place it in a hashtable.

Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0


Method Detail

isOdd

public boolean isOdd()
Determines if this CryptoInteger is odd.

Returns:
Returns true if and only if this CryptoInteger is odd.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

compareTo

public int compareTo(CryptoInteger other)
Compares this CryptoInteger with the specified CryptoInteger.

Parameters:
other - The CryptoInteger to which this CryptoInteger is to be compared.
Returns:
Returns an integer less than, equal to, or greater than 0 if this CryptoInteger is numerically less than, equal to, or greater than other.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

compareTo

public int compareTo(int other)
Compares this CryptoInteger with the specified integer value.

Parameters:
other - An integer to which this CryptoInteger is to be compared.
Returns:
An integer less than, equal to, or greater than 0 if this CryptoInteger is numerically less than, equal to, or greater than other.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

increment

public void increment(CryptoInteger a,
                      CryptoInteger modulus)
               throws ArithmeticException
Increments this CryptoInteger by a, all modulo modulus.

Parameters:
a - The CryptoInteger to be added to this.
modulus - The modulus under which the increment is performed.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

increment

public void increment(int a,
                      CryptoInteger modulus)
               throws ArithmeticException
Increments this CryptoInteger by a, all modulo modulus.

Parameters:
a - The int to be added to this.
modulus - The modulus under which the increment is performed.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

decrement

public void decrement(CryptoInteger a,
                      CryptoInteger modulus)
               throws ArithmeticException
Decrements this CryptoInteger by a, all modulo modulus.

Parameters:
a - The CryptoInteger to be subtracted from this.
modulus - The modulus under which the decrement is performed.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

decrement

public void decrement(int a,
                      CryptoInteger modulus)
               throws ArithmeticException
Decrements this CryptoInteger by a, all modulo modulus.

Parameters:
a - The int to be subtracted from this.
modulus - The modulus under which the decrement is performed.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

multiplyByTwo

public void multiplyByTwo(CryptoInteger modulus)
                   throws ArithmeticException
Multiplies this by two, modulo modulus.

Parameters:
modulus - the modulus under which the multiplication is performed
Throws:
ArithmeticException - modulus is zero
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

divideByTwo

public void divideByTwo(CryptoInteger modulus)
                 throws ArithmeticException
Divides this by two modulo modulus. i.e. the resulting value * 2 will be equivalent to this mod modulus. If modulus is even, there are two possible results; here we return the solution that is in the range [0, this/2 - 1].
NOTE: The result of the operation does not exist if this is odd and modulus is even.

Parameters:
modulus - The modulus under which the division is performed. If this is odd, then modulus must be odd.
Throws:
ArithmeticException - Thrown if the modulus is zero or this is odd and modulus is even.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

add

public CryptoInteger add(CryptoInteger a,
                         CryptoInteger modulus)
                  throws ArithmeticException
Returns a CryptoInteger whose value is (this + a) mod modulus.

Parameters:
a - The CryptoInteger to be added to this.
modulus - The modulus under which the sum is performed.
Returns:
The value: (this + a) mod modulus.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

subtract

public CryptoInteger subtract(CryptoInteger a,
                              CryptoInteger modulus)
                       throws ArithmeticException
Returns a CryptoInteger whose value is (this - a) mod modulus.

Parameters:
a - The CryptoInteger to be subtracted from this.
modulus - The modulus under which the subtraction is performed.
Returns:
Returns (this - a) mod modulus.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

multiply

public CryptoInteger multiply(CryptoInteger a,
                              CryptoInteger modulus)
                       throws ArithmeticException
Returns a CryptoInteger whose value is (this * a) mod modulus.

Parameters:
a - The CryptoInteger to be multiplied into this.
modulus - The modulus under which the multiplication is performed.
Returns:
Returns the value of (this * a) mod modulus.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

square

public CryptoInteger square(CryptoInteger modulus)
                     throws ArithmeticException
Returns a CryptoInteger whose value is this2 mod modulus.

Parameters:
modulus - The modulus under which the squaring is performed.
Returns:
Returns the value of this2 mod modulus.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

invert

public CryptoInteger invert(CryptoInteger modulus)
                     throws ArithmeticException
Returns the inverse of this modulo modulus.

That is, this.invert(modulus) * this is equivalent to 1 modulo modulus.

Parameters:
modulus - The modulus under which the inverse is taken.
Returns:
Returns the value of this-1 mod modulus.
Throws:
ArithmeticException - Thrown if the modulus is zero or this CryptoInteger has no multiplicative inverse mod modulus.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

mod

public CryptoInteger mod(CryptoInteger modulus)
                  throws ArithmeticException
Returns a CryptoInteger whose value is this mod modulus.

Parameters:
modulus - The modulus under which this is reduced.
Returns:
Returns the value of this mod modulus.
Throws:
ArithmeticException - Thrown if the modulus is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

gcd

public CryptoInteger gcd(CryptoInteger a)
Returns the greatest common denominator of this and a.

If both this and a are zero, the result is zero.

Parameters:
a - The value with which the GCD is to be computed.
Returns:
Returns the value of GCD( this, a ).
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

exponent

public CryptoInteger exponent(CryptoInteger exponent,
                              CryptoInteger modulus)
                       throws ArithmeticException
Returns a CryptoInteger whose value is thisexponent mod modulus.

Parameters:
exponent - The CryptoInteger that this is taken to the power of.
modulus - The modulus under which the exponentation is performed.
Returns:
Returns the value of thisexponent mod modulus.
Throws:
ArithmeticException - Thrown if the modulus or the exponent is zero.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

toByteArray

public byte[] toByteArray()
Returns the byte array representation of the value.

The first byte in the array is considered most significant. The leading zero bytes are stripped.

Returns:
A byte array containing the value.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

toByteArray

public byte[] toByteArray(int length)
Returns the byte array representation of the value, padded or truncated to the specified length.

The first byte in the array is considered most significant. A returned array that is 0 or >256 bytes long cannot be passed into the CryptoInteger constructor.

Parameters:
length - The desired byte array length, must be non-negative.
Returns:
The padded or truncated byte array representation of the value.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

toString

public String toString()
Returns the hexadecimal string representation of the value. The first character in the string is considered most significant. The leading zero character pairs are stripped. The returned string will use lowercase characters.

Overrides:
toString in class Object
Returns:
A hexadecimal String representing the value.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

toString

public String toString(int numberOfBytes)
Returns the hexadecimal string representation of the value, padded or truncated to the specified number of bytes (the string length will be twice this number).

The first character in the string is considered most significant. The returned string will use lowercase characters.

Parameters:
numberOfBytes - The number of bytes of the value to be represented in the string.
Returns:
The truncated or padded hexadecimal string representation of the value.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

hashCode

public int hashCode()
Description copied from class: Object
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0

equals

public boolean equals(Object obj)
Description copied from class: Object
Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation:

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any reference values x and y, this method returns true if and only if x and y refer to the same object (x==y has the value true).

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Boolean.hashCode(), Hashtable
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 3.6.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal