net.rim.device.api.crypto
Class Crypto

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

public final class Crypto
extends Object

This class provides a simple API for doing common cryptographic operations.

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

Field Summary
Category: Signed static int PRNG_TYPE_AES_CTR_DRBG
          Flag to specify that an AES CTR Deterministic Random Byte Generator (DRBG) should be used as the Pseudo-Random Number Generator (PRNG).
Category: Signed static int PRNG_TYPE_FIPS186
          Flag to specify that a FIPS186 Random Number Generator should be used as the Pseudo-Random Number Generator (PRNG).
 
Method Summary
Category: Signed static boolean checkMAC(byte[] data, int dataOffset, int dataLength, SymmetricKey key, String algorithm, byte[] mac, int macOffset, int macLength)
          Returns true if the given MAC matches the generated MAC of the given data and the given key using the given algorithm.
Category: Signed static byte[] decrypt(byte[] ciphertext, int offset, int length, Key key, String algorithm, InitializationVector iv)
          Decrypts the given ciphertext with the given key using the given algorithm.
Category: Signed static byte[] encrypt(byte[] plaintext, int offset, int length, Key key, String algorithm, InitializationVector iv)
          Encrypts the given plaintext with the given key using the given algorithm.
Category: Signed static byte[] getDigest(byte[] data, int offset, int length, String algorithm)
          Returns the digest of the given data using the given algorithm.
Category: Signed static byte[] getMAC(byte[] data, int offset, int length, SymmetricKey key, String algorithm)
          Returns the MAC of the given data and the given key using the given algorithm.
Category: Signed static byte[] getPRNG(byte[] seed, int seedOffset, int seedLength, int outputLength)
          Expands a finite length seed into an arbitrarily long stream of pseudo-random bytes using the FIPS-186 Pseudo-Random Number Generator (PRNG).
Category: Signed static byte[] getPRNG(byte[] seed, int seedOffset, int seedLength, int outputLength, int prngType)
          Expands a finite length seed into an arbitrarily long stream of pseudo-random bytes using the specified Pseudo-Random Number Generator (PRNG).
Category: Signed static byte[] sign(byte[] data, int offset, int length, PrivateKey key, String signingAlgorithm, String encodingAlgorithm)
          Returns the signature of the given private key on the given data, using the given algorithm.
Category: Signed static boolean verify(byte[] data, int dataOffset, int dataLength, PublicKey key, String encodingAlgorithm, byte[] encodedSignature, int encodedSignatureOffset)
          Returns true if the given signature verifies with the given public key on the given data, using the given algorithm.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Field Detail

PRNG_TYPE_FIPS186

public static final int PRNG_TYPE_FIPS186
Flag to specify that a FIPS186 Random Number Generator should be used as the Pseudo-Random Number Generator (PRNG).

Note: This PRNG is no longer FIPS compliant. If a FIPS compliant PRNG is required, use the AES CTR DRBG instead.

See Also:
Constant Field Values
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 7.0.0

PRNG_TYPE_AES_CTR_DRBG

public static final int PRNG_TYPE_AES_CTR_DRBG
Flag to specify that an AES CTR Deterministic Random Byte Generator (DRBG) should be used as the Pseudo-Random Number Generator (PRNG).

See Also:
Constant Field Values
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 7.0.0


Method Detail

encrypt

public static byte[] encrypt(byte[] plaintext,
                             int offset,
                             int length,
                             Key key,
                             String algorithm,
                             InitializationVector iv)
                      throws NoSuchAlgorithmException,
                             CryptoException,
                             IllegalArgumentException
Encrypts the given plaintext with the given key using the given algorithm. Any algorithm supported by EncryptorFactory is supported.

Parameters:
plaintext - The data to be encrypted.
offset - The start of the data.
length - The length of the data.
key - The encryption key. Note that this may be a SymmetricKey or a PublicKey.
algorithm - Describes the algorithm to use, such as "TripleDES/CBC/PKCS5", "RSA/PKCS1". May be null.
iv - The optional InitializationVector to be used if needed. May be null. Some encryption modes, such as CBC, require an IV, while others do not.
Returns:
The ciphertext.
Throws:
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
See Also:
EncryptorFactory, EncryptorOutputStream, InitializationVectorFactory, SymmetricKeyFactory, SymmetricKeyDecoder, PublicKeyDecoder
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

decrypt

public static byte[] decrypt(byte[] ciphertext,
                             int offset,
                             int length,
                             Key key,
                             String algorithm,
                             InitializationVector iv)
                      throws NoSuchAlgorithmException,
                             CryptoException,
                             IllegalArgumentException
Decrypts the given ciphertext with the given key using the given algorithm. Any algorithm supported by DecryptorFactory is supported.

Parameters:
ciphertext - The data to be decrypted.
offset - The start of the data.
length - The length of the data.
key - The decryption key. Note that this may be a SymmetricKey or a PrivateKey.
algorithm - Describes the algorithm to use, eg "TripleDES/CBC/PKCS5", "RSA/PKCS1". May be null. See Crypto Algorithms.
iv - The optional InitializationVector to be used if needed. This may be null . Some encryption modes, eg CBC, require an IV, while others do not.
Returns:
The plaintext.
Throws:
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
See Also:
DecryptorFactory, DecryptorInputStream, InitializationVectorFactory, SymmetricKeyFactory, SymmetricKeyDecoder, PublicKeyDecoder
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

getDigest

public static byte[] getDigest(byte[] data,
                               int offset,
                               int length,
                               String algorithm)
                        throws NoSuchAlgorithmException,
                               CryptoException
Returns the digest of the given data using the given algorithm.

Parameters:
data - The data to be digested.
offset - The start of the data.
length - The length of the data.
algorithm - Describes the algorithm to use, such as "SHA1" or "MD5". See Crypto Algorithms.
Returns:
The digest.
Throws:
NoSuchAlgorithmException
CryptoException
See Also:
DigestFactory, Digest
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

getMAC

public static byte[] getMAC(byte[] data,
                            int offset,
                            int length,
                            SymmetricKey key,
                            String algorithm)
                     throws NoSuchAlgorithmException,
                            CryptoException,
                            IllegalArgumentException
Returns the MAC of the given data and the given key using the given algorithm.

Parameters:
data - The data to be input to the MAC algorithm.
offset - The start of the data.
length - The length of the data.
key - The key to use to generate the MAC
algorithm - Describes the algorithm to use, eg "HMAC/SHA1", "CBCMAC/DES". See Crypto Algorithms.
Returns:
The MAC.
Throws:
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
See Also:
MACFactory, MAC
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

checkMAC

public static boolean checkMAC(byte[] data,
                               int dataOffset,
                               int dataLength,
                               SymmetricKey key,
                               String algorithm,
                               byte[] mac,
                               int macOffset,
                               int macLength)
                        throws NoSuchAlgorithmException,
                               CryptoException,
                               IllegalArgumentException
Returns true if the given MAC matches the generated MAC of the given data and the given key using the given algorithm.

Parameters:
data - The data to be digested.
dataOffset - The start of the data.
dataLength - The length of the data.
key - The key to use to generate the MAC
algorithm - Describes the algorithm to use; for example, "HMAC/SHA1", "CBCMAC/DES".
mac - The data of the given MAC.
macOffset - The start of the MAC data.
macLength - The length of the MAC data.
Returns:
The MAC.
Throws:
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
See Also:
MACFactory, MAC
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

sign

public static byte[] sign(byte[] data,
                          int offset,
                          int length,
                          PrivateKey key,
                          String signingAlgorithm,
                          String encodingAlgorithm)
                   throws NoSuchAlgorithmException,
                          CryptoException,
                          IllegalArgumentException
Returns the signature of the given private key on the given data, using the given algorithm.

Parameters:
data - The data to be signed.
dataOffset - The start of the data.
dataLength - The length of the data.
key - The signing key.
signingAlgorithm - Describes the algorithm to use, eg "RSA_PKCS1", "ECDSA". See Crypto Algorithms.
encodingAlgorithm - Describes how the signature is to be encoded, eg "X509". See Crypto Algorithms.
Returns:
The encoded signature.
Throws:
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
See Also:
SignatureSignerFactory, SignatureSigner, EncodedSignature
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

verify

public static boolean verify(byte[] data,
                             int dataOffset,
                             int dataLength,
                             PublicKey key,
                             String encodingAlgorithm,
                             byte[] encodedSignature,
                             int encodedSignatureOffset)
                      throws NoSuchAlgorithmException,
                             CryptoException,
                             IllegalArgumentException
Returns true if the given signature verifies with the given public key on the given data, using the given algorithm.

Parameters:
data - The data that was signed.
dataOffset - The start of the data.
dataLength - The length of the data.
key - The verifying key.
encodingAlgorithm - Describes how the signature was encoded; for example, "X509".
encodedSignature - The encoded signature.
encodedSignatureOffset - The start of the encoded signature.
Throws:
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
See Also:
SignatureDecoder, DecodedSignature, SignatureVerifier
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

getPRNG

public static byte[] getPRNG(byte[] seed,
                             int seedOffset,
                             int seedLength,
                             int outputLength)
Expands a finite length seed into an arbitrarily long stream of pseudo-random bytes using the FIPS-186 Pseudo-Random Number Generator (PRNG).

Note: This PRNG is no longer FIPS compliant. If FIPS compliancy is required, the overload of the getPRNG method should be called with PRNG_TYPE_AES_CTR_DRBG as the prngType.

Parameters:
seed - The seed data.
seedOffset - The start of the seed.
seedLength - The length of the seed.
outputLength - The requested number of pseudo-random bytes.
Returns:
A byte array containing the pseudo-random bytes.
See Also:
FIPS186PseudoRandomSource, RandomSource, Random
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

getPRNG

public static byte[] getPRNG(byte[] seed,
                             int seedOffset,
                             int seedLength,
                             int outputLength,
                             int prngType)
Expands a finite length seed into an arbitrarily long stream of pseudo-random bytes using the specified Pseudo-Random Number Generator (PRNG).

Supported values for prngType are:

Parameters:
seed - The seed data.
seedOffset - The start of the seed.
seedLength - The length of the seed.
outputLength - The requested number of pseudo-random bytes.
prngType - The type of PRNG to be used.
Returns:
A byte array containing the pseudo-random bytes.
Throws:
IllegalArgumentException - If an invalid prngType is specified.
See Also:
AESCTRDRBGPseudoRandomSource, FIPS186PseudoRandomSource, RandomSource, Random
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 7.0.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