net.rim.device.api.crypto
Class EncryptorFactory

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

public abstract class EncryptorFactory
extends Object

Provides the user with a high-level means to encrypt data. The factory classes allow you to encrypt (see the DecryptorFactory class) and decrypt data without worrying about most of the minute details of the implementation. This class is suitable for developers with little cryptographic experience or, for encrypting data where the details of the implementation are not as important as the result.

The low-level alternative to using the EncryptorFactory class is the encryptor engine, such as the DESEncryptorEngine.

Note: When requesting a a block cipher in CFB mode you can specify the number of bits to be processed at a time. In our API there are two options allowed for CFB mode. You can either have 8bit mode (denoted by "CFB8") or full CFB mode (denoted simply by "CFB") which will process the full block length.

Note: When calling the getEncryptorOutputStream functions, if you specify the algorithm as just "RSA", or just pass in an RSAPublicKey, then what will be created is "RSA/PKCS1". This is because there are alot of problems with using RSA, by itself, with block encryption/decryption. To use the basic RSA function by itself, use the engine directly.

Note: When using the ElGamal Encryption algorithm it will automatically create an ephemeral localKeyPair for you and append that public key encoding to the front of the returned ciphertext according to the MPI format described in PGP. If you wish to use another format for ElGamal encryption use the engine directly.

For more information on the cryptographic algorithms supported by this factory, see Crypto Algorithms.

NOTE: The implementation of this class may return an object that uses functionality provided by Certicom. In such cases, the calling code must have a license with Certicom, and be signed with the RCC code signing key. If the RCC code signature check fails, then a ControlledAccessException is thrown. For more information on the classes that use technology from Certicom, see Crypto Algorithms.

See Also:
ControlledAccessException, RSAEncryptorEngine, ElGamalEncryptorEngine, DecryptorFactory, EncryptorOutputStream
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 EncryptorFactory()
          Creates an EncryptorFactory object.
 
Method Summary
Category: Signed protected abstract  Object create(String algorithm, String nextAlgorithm, Key key, OutputStream stream, InitializationVector iv)
          Creates an instance of the EncryptorFactory class given the specified parameters.
Category: Signed static Enumeration getAlgorithms()
          Returns an Enumeration of String representing all of the registered algorithms with this factory.
Category: Signed static BlockEncryptorEngine getBlockEncryptorEngine(Key key)
          Returns the block encryptor engine used to encrypt the data.
Category: Signed static BlockEncryptorEngine getBlockEncryptorEngine(Key key, String algorithm)
          Returns the block encryptor engine using the specified key and algorithm.
Category: Signed static BlockEncryptorEngine getBlockEncryptorEngine(Key key, String algorithm, InitializationVector iv)
          Returns the block encryptor engine using the specified key, algorithm and initialization vector.
Category: Signed static EncryptorOutputStream getEncryptorOutputStream(Key key, OutputStream stream)
          Encrypts the data and returns the encrypted output stream given the specified key and output stream.
Category: Signed static EncryptorOutputStream getEncryptorOutputStream(Key key, OutputStream stream, String algorithm)
          Encrypts the data and returns the encrypted output stream given the specified key, outputstream and algorithm name.
Category: Signed static EncryptorOutputStream getEncryptorOutputStream(Key key, OutputStream stream, String algorithm, InitializationVector iv)
          Encrypts the data and returns the encrypted output stream given the specified key, outputstream, algorithm name and initialization vector.
Category: Signed protected abstract  String[] getFactoryAlgorithms()
          Returns a String containing the names of all algorithms supported by the encryptor factory.
Category: Signed static void register(EncryptorFactory factory)
          Registers the specified object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

EncryptorFactory

protected EncryptorFactory()
Creates an EncryptorFactory object.

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

getEncryptorOutputStream

public static EncryptorOutputStream getEncryptorOutputStream(Key key,
                                                             OutputStream stream)
                                                      throws NoSuchAlgorithmException,
                                                             CryptoTokenException,
                                                             CryptoUnsupportedOperationException,
                                                             CryptoException,
                                                             IOException
Encrypts the data and returns the encrypted output stream given the specified key and output stream.

Parameters:
key - The key used to encrypt the data.
stream - The output stream containing the plaintext to be encrypted.
Returns:
The encrypted output stream.
Throws:
NoSuchAlgorithmException - Thrown if the specified symmetric key is improperly formatted or invalid.
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
IOException
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

getEncryptorOutputStream

public static EncryptorOutputStream getEncryptorOutputStream(Key key,
                                                             OutputStream stream,
                                                             String algorithm)
                                                      throws NoSuchAlgorithmException,
                                                             CryptoTokenException,
                                                             CryptoUnsupportedOperationException,
                                                             CryptoException,
                                                             IOException
Encrypts the data and returns the encrypted output stream given the specified key, outputstream and algorithm name.

Parameters:
key - The key used to encrypt the data.
stream - The output stream containing the plaintext to be encrypted.
algorithm - A string that represents the algorithm along with the details of the encryption. eg, "RC5_64_64" ("RC5_" + keyBitLength + "_" + blockBitLength). The string, consisting of one or more substrings, is read from right to left with the left-most sub-string representing the name of the algorithm. The two substrings to the right of the algorithm specify the length of the key in bits and the block length of the data in bits.

If a substring is not defined, the default value is substituted instead.

Returns:
The output stream to contain the encrypted data.
Throws:
NoSuchAlgorithmException - Thrown if the specified symmetric key is improperly formatted or invalid.
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
IOException
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

getEncryptorOutputStream

public static EncryptorOutputStream getEncryptorOutputStream(Key key,
                                                             OutputStream stream,
                                                             String algorithm,
                                                             InitializationVector iv)
                                                      throws NoSuchAlgorithmException,
                                                             CryptoTokenException,
                                                             CryptoUnsupportedOperationException,
                                                             CryptoException,
                                                             IOException
Encrypts the data and returns the encrypted output stream given the specified key, outputstream, algorithm name and initialization vector.

Parameters:
key - The key used to encrypt the data.
stream - The output stream containing the plaintext to be encrypted.
algorithm - A string that represents the algorithm along with the details of the decryption. eg, "RC5_64_64" ("RC5_" + keyBitLength + "_" + blockBitLength). The string, consisting of one or more substrings, is read from right to left with the left-most sub-string representing the name of the algorithm. The two substrings to the right of the algorithm specify the length of the key in bits and the block length of the data in bits.

If a substring is not defined, the default value is substituted instead.

iv - The initialization vector used to randomize the data.
Returns:
The output stream to contain the encrypted data.
Throws:
NoSuchAlgorithmException - Thrown if the specified symmetric key is improperly formatted or invalid.
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
IOException
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

getBlockEncryptorEngine

public static BlockEncryptorEngine getBlockEncryptorEngine(Key key)
                                                    throws NoSuchAlgorithmException,
                                                           CryptoTokenException,
                                                           CryptoUnsupportedOperationException,
                                                           CryptoException
Returns the block encryptor engine used to encrypt the data.

Parameters:
key - The key used to encrypt the data.
Returns:
The BlockEncryptorEngine object used to encrypt the data.
Throws:
NoSuchAlgorithmException - Thrown if the specified symmetric key is improperly formatted or invalid.
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
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

getBlockEncryptorEngine

public static BlockEncryptorEngine getBlockEncryptorEngine(Key key,
                                                           String algorithm)
                                                    throws NoSuchAlgorithmException,
                                                           CryptoTokenException,
                                                           CryptoUnsupportedOperationException,
                                                           CryptoException
Returns the block encryptor engine using the specified key and algorithm.

Parameters:
key - The key used to encrypt the data.
algorithm - A string that represents the algorithm along with the details of the decryption. eg, "RC5_64_64" ("RC5_" + keyBitLength + "_" + blockBitLength). The string, consisting of one or more substrings, is read from right to left with the left-most sub-string representing the name of the algorithm. The two substrings to the right of the algorithm specify the length of the key in bits and the block length of the data in bits.

If a substring is not defined, the default value is substituted instead.

Returns:
The BlockEncryptorEngine object used to encrypt the data.
Throws:
NoSuchAlgorithmException - Thrown if the specified symmetric key is improperly formatted or invalid.
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
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

getBlockEncryptorEngine

public static BlockEncryptorEngine getBlockEncryptorEngine(Key key,
                                                           String algorithm,
                                                           InitializationVector iv)
                                                    throws NoSuchAlgorithmException,
                                                           CryptoTokenException,
                                                           CryptoUnsupportedOperationException,
                                                           CryptoException
Returns the block encryptor engine using the specified key, algorithm and initialization vector.

Parameters:
key - The key used to encrypt the data.
algorithm - A string that represents the algorithm along with the details of the decryption. eg, "RC5_64_64" ("RC5_" + keyBitLength + "_" + blockBitLength). The string, consisting of one or more substrings, is read from right to left with the left-most sub-string representing the name of the algorithm. The two substrings to the right of the algorithm specify the length of the key in bits and the block length of the data in bits.

If a substring is not defined, the default value is substituted instead.

iv - The initialization vector used to randomize the data.
Returns:
The BlockEncryptorEngine object used to encrypt the data.
Throws:
NoSuchAlgorithmException - Thrown if the specified symmetric key is improperly formatted or invalid.
CryptoTokenException - Thrown if an error occurs with the crypto token or the crypto token is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
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

register

public static void register(EncryptorFactory factory)
Registers the specified object.

If a factory with the same name already exists, then this factory will not be added.

Parameters:
factory - The encryptor factory to be registered.
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

getAlgorithms

public static Enumeration getAlgorithms()
Returns an Enumeration of String representing all of the registered algorithms with this factory.

Returns:
An Enumeration of Strings representing all of the registered algorithms with this factory.
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

getFactoryAlgorithms

protected abstract String[] getFactoryAlgorithms()
Returns a String containing the names of all algorithms supported by the encryptor factory.

Returns:
A String array containing the names of all supported 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:
BlackBerry API 3.6.0

create

protected abstract Object create(String algorithm,
                                 String nextAlgorithm,
                                 Key key,
                                 OutputStream stream,
                                 InitializationVector iv)
                          throws NoSuchAlgorithmException,
                                 ClassCastException,
                                 CryptoTokenException,
                                 CryptoUnsupportedOperationException,
                                 CryptoException,
                                 IOException
Creates an instance of the EncryptorFactory class given the specified parameters.

Parameters:
algorithm - String that specifies the details of the encryption scheme. The string is composed of three separate strings concatenated together and delimited by forward slashes. For example DES/CBC/OAEP represents a valid string that specifies the cipher, the mode and the formatter engine that will be used to encrypt the data. The algorithm parameter corresponds to the rightmost substring. The null value is passed if an element is not specified. The null value specifies that the default value be used.
nextAlgorithm - A String that represents the next substring to the left of the initial algorithm parameter specified above.
key - The key used to encrypt the data.
stream - The OutputStream that contains the ciphertext of the initial message.
iv - The initialization vector initially used by the encryptor engine to randomize the data.
Returns:
The EncryptorFactory object.
Throws:
NoSuchAlgorithmException - Occurs when the specified algorithm is invalid.
ClassCastException - Occurs when an object is improperly cast.
CryptoTokenException - Occurs when the crypto token is invalid.
CryptoUnsupportedOperationException - Thrown if a call is made to an unsupported operation.
CryptoException
IOException
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-2010 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. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.