SHOW Signed
 

net.rim.device.api.crypto
Class Crypto

java.lang.Object
  |
  +--net.rim.device.api.crypto.Crypto

public final class Crypto
extends Object

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

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.

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:
ControlledAccessException

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 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[] 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
 

Method Detail

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, eg "HMAC/SHA1", "CBCMAC/DES". See Crypto Algorithms.
mac - the data of the given MAC.
macOffset - the start of the MAC data.
macLength - the length of the MAC data.
Returns:
the MAC.
Since:
JDE 3.6.0
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.

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.
Since:
JDE 3.6.0
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.

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 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, 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 ciphertext.
Since:
JDE 3.6.0
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.

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, eg "SHA1", "MD5". See Crypto Algorithms.
Returns:
the digest.
Since:
JDE 3.6.0
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.

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.
Since:
JDE 3.6.0
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.

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).
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.
Since:
JDE 3.6.0
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.

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.
Since:
JDE 3.6.0
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.

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, eg "X509". See Crypto Algorithms.
encodedSignature - the encoded signature.
encodedSignatureOffset - the start of the encoded signature.
Since:
JDE 3.6.0
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.



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.