|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.rim.device.api.crypto.Crypto
public final class Crypto
This class provides a simple API for doing common cryptographic operations.
| Method Summary | ||
|---|---|---|
|
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. |
|
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. |
|
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. |
|
static byte[] |
getDigest(byte[] data,
int offset,
int length,
String algorithm)
Returns the digest of the given data using the given algorithm. |
|
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. |
|
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). |
|
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. |
|
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 |
|---|
public static byte[] encrypt(byte[] plaintext,
int offset,
int length,
Key key,
String algorithm,
InitializationVector iv)
throws NoSuchAlgorithmException,
CryptoException,
IllegalArgumentException
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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentExceptionEncryptorFactory,
EncryptorOutputStream,
InitializationVectorFactory,
SymmetricKeyFactory,
SymmetricKeyDecoder,
PublicKeyDecoder
public static byte[] decrypt(byte[] ciphertext,
int offset,
int length,
Key key,
String algorithm,
InitializationVector iv)
throws NoSuchAlgorithmException,
CryptoException,
IllegalArgumentException
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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentExceptionDecryptorFactory,
DecryptorInputStream,
InitializationVectorFactory,
SymmetricKeyFactory,
SymmetricKeyDecoder,
PublicKeyDecoder
public static byte[] getDigest(byte[] data,
int offset,
int length,
String algorithm)
throws NoSuchAlgorithmException,
CryptoException
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.
NoSuchAlgorithmException
CryptoExceptionDigestFactory,
Digest
public static byte[] getMAC(byte[] data,
int offset,
int length,
SymmetricKey key,
String algorithm)
throws NoSuchAlgorithmException,
CryptoException,
IllegalArgumentException
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 MACalgorithm - describes the algorithm to use, eg "HMAC/SHA1", "CBCMAC/DES". See Crypto Algorithms.
NoSuchAlgorithmException
CryptoException
IllegalArgumentExceptionMACFactory,
MAC
public static boolean checkMAC(byte[] data,
int dataOffset,
int dataLength,
SymmetricKey key,
String algorithm,
byte[] mac,
int macOffset,
int macLength)
throws NoSuchAlgorithmException,
CryptoException,
IllegalArgumentException
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 MACalgorithm - 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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentExceptionMACFactory,
MAC
public static byte[] sign(byte[] data,
int offset,
int length,
PrivateKey key,
String signingAlgorithm,
String encodingAlgorithm)
throws NoSuchAlgorithmException,
CryptoException,
IllegalArgumentException
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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentExceptionSignatureSignerFactory,
SignatureSigner,
EncodedSignature
public static boolean verify(byte[] data,
int dataOffset,
int dataLength,
PublicKey key,
String encodingAlgorithm,
byte[] encodedSignature,
int encodedSignatureOffset)
throws NoSuchAlgorithmException,
CryptoException,
IllegalArgumentException
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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentExceptionSignatureDecoder,
DecodedSignature,
SignatureVerifier
public static byte[] getPRNG(byte[] seed,
int seedOffset,
int seedLength,
int outputLength)
seed - the seed data.seedOffset - the start of the seed.seedLength - the length of the seed.outputLength - the requested number of pseudo-random bytes.
FIPS186PseudoRandomSource,
RandomSource,
Random
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
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.