

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object net.rim.device.api.crypto.CryptoInteger
public class CryptoInteger
Represents large unsigned integer arithmetic class.
Most operations are performed with respect to a modulus.
Constructor Summary  


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


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


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


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


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


CryptoInteger(CryptoInteger other)
Creates a copy of a given CryptoInteger instance. 
Method Summary  


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

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

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

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

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

void 
divideByTwo(CryptoInteger modulus)
Divides this by two modulo modulus . i.e. the resulting value * 2 will
be equivalent to this mod modulus . 

boolean 
equals(Object obj)
Indicates whether some other object is "equal to" this one. 

CryptoInteger 
exponent(CryptoInteger exponent,
CryptoInteger modulus)
Returns a CryptoInteger whose value is this^{exponent} mod modulus . 

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

int 
hashCode()
Returns a hash code value for the object. 

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

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

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

boolean 
isOdd()
Determines if this CryptoInteger is odd. 

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

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

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

CryptoInteger 
square(CryptoInteger modulus)
Returns a CryptoInteger whose value is this^{2} mod modulus . 

CryptoInteger 
subtract(CryptoInteger a,
CryptoInteger modulus)
Returns a CryptoInteger whose value is (this  a) mod modulus . 

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

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

String 
toString()
Returns the hexadecimal string representation of the value. 

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 

public CryptoInteger(int value)
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.
value
 The integer representation of the nonnegative value.public CryptoInteger(byte[] value)
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 1256.
Note: This object is mutable, and therefore so is the hash code. Don't modify this object after you place it in a hashtable.
value
 The byte array representation of the value.public CryptoInteger(byte[] value, int offset, int length)
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.
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 1256.public CryptoInteger(String value)
CryptoInteger
object with the given hexadecimal
string.
Characters must be 09, AF, or af. 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.
value
 The hexadecimal string representation of the value.public CryptoInteger(CryptoInteger other)
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.
other
 The CryptoInteger
object to be copied.protected CryptoInteger()
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.
Method Detail 

public boolean isOdd()
CryptoInteger
is odd.
true
if and only if this CryptoInteger
is odd.public int compareTo(CryptoInteger other)
CryptoInteger
with the specified
CryptoInteger
.
other
 The CryptoInteger
to which this CryptoInteger
is to be compared.
CryptoInteger
is numerically
less than, equal to, or greater than other
.public int compareTo(int other)
CryptoInteger
with the specified integer value.
other
 An integer to which this CryptoInteger
is to be compared.
CryptoInteger
is numerically
less than, equal to, or greater than other
.public void increment(CryptoInteger a, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
by a
, all modulo modulus
.
a
 The CryptoInteger
to be added to this
.modulus
 The modulus under which the increment is performed.
ArithmeticException
 Thrown if the modulus is zero.public void increment(int a, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
by a
, all modulo modulus
.
a
 The int to be added to this
.modulus
 The modulus under which the increment is performed.
ArithmeticException
 Thrown if the modulus is zero.public void decrement(CryptoInteger a, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
by a
, all modulo modulus
.
a
 The CryptoInteger
to be subtracted from this
.modulus
 The modulus under which the decrement is performed.
ArithmeticException
 Thrown if the modulus is zero.public void decrement(int a, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
by a
, all modulo modulus
.
a
 The int to be subtracted from this
.modulus
 The modulus under which the decrement is performed.
ArithmeticException
 Thrown if the modulus is zero.public void multiplyByTwo(CryptoInteger modulus) throws ArithmeticException
this
by two, modulo modulus
.
modulus
 the modulus under which the multiplication is performed
ArithmeticException
 modulus is zeropublic void divideByTwo(CryptoInteger modulus) throws ArithmeticException
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
]. this
is odd and
modulus
is even.
modulus
 The modulus under which the division is performed. If this
is odd, then
modulus
must be odd.
ArithmeticException
 Thrown if the modulus
is zero or this
is odd and modulus
is even.public CryptoInteger add(CryptoInteger a, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
whose value is (this + a) mod modulus
.
a
 The CryptoInteger
to be added to this
.modulus
 The modulus under which the sum is performed.
(this + a) mod modulus
.
ArithmeticException
 Thrown if the modulus is zero.public CryptoInteger subtract(CryptoInteger a, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
whose value is (this  a) mod modulus
.
a
 The CryptoInteger
to be subtracted from this
.modulus
 The modulus under which the subtraction is performed.
(this  a) mod modulus
.
ArithmeticException
 Thrown if the modulus is zero.public CryptoInteger multiply(CryptoInteger a, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
whose value is (this * a) mod modulus
.
a
 The CryptoInteger
to be multiplied into this
.modulus
 The modulus under which the multiplication is performed.
(this * a) mod modulus
.
ArithmeticException
 Thrown if the modulus is zero.public CryptoInteger square(CryptoInteger modulus) throws ArithmeticException
CryptoInteger
whose value is this^{2} mod modulus
.
modulus
 The modulus under which the squaring is performed.
this^{2} mod modulus
.
ArithmeticException
 Thrown if the modulus is zero.public CryptoInteger invert(CryptoInteger modulus) throws ArithmeticException
this
modulo modulus
.
That is, this.invert(modulus) * this
is equivalent to 1 modulo modulus
.
modulus
 The modulus under which the inverse is taken.
this^{1} mod modulus
.
ArithmeticException
 Thrown if the modulus is zero or this
CryptoInteger
has no multiplicative inverse mod modulus
.public CryptoInteger mod(CryptoInteger modulus) throws ArithmeticException
CryptoInteger
whose value is this mod modulus
.
modulus
 The modulus under which this
is reduced.
this mod modulus
.
ArithmeticException
 Thrown if the modulus is zero.public CryptoInteger gcd(CryptoInteger a)
this
and
a
.
If both this
and a
are zero, the result is zero.
a
 The value with which the GCD is to be computed.
GCD( this, a )
.public CryptoInteger exponent(CryptoInteger exponent, CryptoInteger modulus) throws ArithmeticException
CryptoInteger
whose value is this^{exponent} mod modulus
.
exponent
 The CryptoInteger
that this
is taken to the power of.modulus
 The modulus under which the exponentation is performed.
this^{exponent} mod modulus
.
ArithmeticException
 Thrown if the modulus or the exponent is zero.public byte[] toByteArray()
The first byte in the array is considered most significant. The leading zero bytes are stripped.
public byte[] toByteArray(int 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.
length
 The desired byte array length, must be nonnegative.
public String toString()
toString
in class Object
public String toString(int numberOfBytes)
The first character in the string is considered most significant. The returned string will use lowercase characters.
numberOfBytes
 The number of bytes of the value to be represented in the string.
public int hashCode()
Object
java.util.Hashtable
.
The general contract of hashCode
is:
hashCode
method on each of
the two objects must produce the same integer result.
Object.equals(java.lang.Object)
method, then calling the hashCode method on each of the
two objects must produce distinct integer results. However, the
programmer should be aware that producing distinct integer results
for unequal objects may improve the performance of hashtables.
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 Java^{TM} programming language.)
hashCode
in class Object
Object.equals(java.lang.Object)
,
Hashtable
public boolean equals(Object obj)
Object
The equals
method implements an equivalence relation:
x
,
x.equals(x)
should return true
.
x
and
y
, x.equals(y)
should return
true
if and only if y.equals(x)
returns
true
.
x
,
y
, and z
, if x.equals(y)
returns true
and y.equals(z)
returns
true
, then x.equals(z)
should return
true
.
x
and y
, multiple invocations of x.equals(y)
consistently return true
or consistently return
false
, provided no information used in
equals
comparisons on the object is modified.
x
,
x.equals(null)
should return false
.
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
).
equals
in class Object
obj
 the reference object with which to compare.
true
if this object is the same as the obj
argument; false
otherwise.Boolean.hashCode()
,
Hashtable


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
Copyright 19992011 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