SHOW Signed
 

net.rim.device.api.crypto
Class ARC4PseudoRandomSource

java.lang.Object
  |
  +--net.rim.device.api.crypto.AbstractPseudoRandomSource
        |
        +--net.rim.device.api.crypto.ARC4PseudoRandomSource
All Implemented Interfaces:
PseudoRandomSource

public final class ARC4PseudoRandomSource
extends AbstractPseudoRandomSource
implements PseudoRandomSource

Represents a pseudo-random number generator (PRNG) that uses the Alledged RC4 (ARC4) algorithm to expand a finite length seed into an arbitrarily long stream of pseudo-random bytes.

We implemented ARC4 as described in "Applied Cryptography", by Bruce Schneier, in Section 17.1 ( published 1996 ).

ARC4 is a version of the proprietary RC4 algorithm that was supposedly released onto the Internet in 1994. RC4 is a variable key size stream cipher developed in 1987 by Ron Rivest for RSA Data Security Inc. The algorithm is very simple and works in OFB mode where the keystream is independent of the plaintext.

For a code sample using the ARC4 pseudo random source, click here.

For information on cryptographic algorithms, see Crypto Algorithms.

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:
JDE 3.6.0
See Also:
ARC4Key

Constructor Summary
 Category: Signed ARC4PseudoRandomSource(ARC4Key key)
          Creates an ARC4PseudoRandomSource object using the specified ARC4Key to initialize the pseudo-random source.
 Category: Signed ARC4PseudoRandomSource(byte[] seed)
          Creates an ARC4PseudoRandomSource object with the given (secret) seed data.
 Category: Signed ARC4PseudoRandomSource(byte[] seed, int offset, int length)
          Creates an ARC4PseudoRandomSource object with the given (secret) seed data.
 
Method Summary
 Category: Signed  String getAlgorithm()
          Returns the name of the algorithm used, ie "ARC4".
 Category: Signed  int getAvailable()
          Returns an integer that specifies the number of pseudo-random bytes currently available (this value is reset to the value returned by getMaxAvailable() with calls to reset()).
 Category: Signed  int getMaxAvailable()
          Returns the maximum number of pseudo-random bytes that this PRNG can produce following a call to reset().
 Category: Signed  void xorBytes(byte[] buffer, int offset, int length)
          Exclusive-OR's random bytes into the given buffer starting at the specified array offset.
 
Methods inherited from class net.rim.device.api.crypto.AbstractPseudoRandomSource
getBytes, getBytes, getBytes, xorBytes, xorBytes, xorCopy, xorCopy
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.rim.device.api.crypto.PseudoRandomSource
getBytes, getBytes, getBytes, xorBytes, xorBytes, xorCopy, xorCopy
 

Constructor Detail

ARC4PseudoRandomSource

public ARC4PseudoRandomSource(ARC4Key key)
                       throws CryptoTokenException
Creates an ARC4PseudoRandomSource object using the specified ARC4Key to initialize the pseudo-random source.

Parameters:
key - The ARC4 key used to seed the random source.
Throws:
CryptoTokenException - Thrown when a problem occurs with a crypto token or the crypto token is invalid.
Since:
JDE 3.6.0
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.

ARC4PseudoRandomSource

public ARC4PseudoRandomSource(byte[] seed)
Creates an ARC4PseudoRandomSource object with the given (secret) seed data.

Parameters:
seed - The seed data to initialize the random source.
Since:
JDE 3.6.0
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.

ARC4PseudoRandomSource

public ARC4PseudoRandomSource(byte[] seed,
                              int offset,
                              int length)
Creates an ARC4PseudoRandomSource object with the given (secret) seed data.

Parameters:
seed - The seed data for the random source.
offset - The offset, or first bit position, of the seed data in the array.
length - The number of bytes to use from the array.
Since:
JDE 3.6.0
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.
Method Detail

getAlgorithm

public String getAlgorithm()
Returns the name of the algorithm used, ie "ARC4".

This method will always return "ARC4"

Returns:
A string representing the name of the encryption algorithm.
Since:
JDE 3.6.0
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.

getAvailable

public int getAvailable()
Returns an integer that specifies the number of pseudo-random bytes currently available (this value is reset to the value returned by getMaxAvailable() with calls to reset()).

For PRNG sources that have an indefinite length but implement this interface, the value returned is the maximum signed value that will fit into an int.

Returns:
The number of bytes.
Since:
JDE 3.6.0
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.

getMaxAvailable

public int getMaxAvailable()
Returns the maximum number of pseudo-random bytes that this PRNG can produce following a call to reset(). For PRNG sources that have an indefinite length but implement this interface, the value returned is the maximum signed value that will fit into an int.

Returns:
An integer that represents the maximum number of bytes.
Since:
JDE 3.6.0
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.

xorBytes

public void xorBytes(byte[] buffer,
                     int offset,
                     int length)
Exclusive-OR's random bytes into the given buffer starting at the specified array offset.

Specified by:
xorBytes in interface PseudoRandomSource
Overrides:
xorBytes in class AbstractPseudoRandomSource
Parameters:
buffer - The byte array to be xor'ed with random bytes.
offset - The offset, or first bit position, of the data within the array.
length - ie "ARC4". The number of bytes to be xor'ed.
Since:
JDE 3.6.0
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.



Copyright 1999-2009 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.