net.rim.device.api.crypto
Class ARC4PseudoRandomSource

java.lang.Object
  extended by net.rim.device.api.crypto.AbstractPseudoRandomSource
      extended by 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.

See Also:
ARC4Key
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 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.
Category: Signed ARC4PseudoRandomSource(ARC4Key key)
          Creates an ARC4PseudoRandomSource object using the specified ARC4Key to initialize the pseudo-random source.
 
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(byte[] seed)
Creates an ARC4PseudoRandomSource object with the given (secret) seed data.

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

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.
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

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.
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

getAlgorithm

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

This method will always return "ARC4"

Specified by:
getAlgorithm in interface PseudoRandomSource
Returns:
A string representing the name of the encryption algorithm.
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

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
Specified by:
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.
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

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.

Specified by:
getAvailable in interface PseudoRandomSource
Returns:
The number of bytes.
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

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.

Specified by:
getMaxAvailable in interface PseudoRandomSource
Returns:
An integer that represents the maximum number of bytes.
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