|
|||||||||
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.
Field Summary | ||
---|---|---|
|
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). |
|
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 | ||
---|---|---|
|
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 the 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[] |
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). |
|
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 |
Field Detail |
---|
public static final int PRNG_TYPE_FIPS186
Note: This PRNG is no longer FIPS compliant. If a FIPS compliant PRNG is required, use the AES CTR DRBG instead.
public static final int PRNG_TYPE_AES_CTR_DRBG
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, 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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
EncryptorFactory
,
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
IllegalArgumentException
DecryptorFactory
,
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, such as "SHA1" or "MD5". See Crypto Algorithms.
NoSuchAlgorithmException
CryptoException
DigestFactory
,
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
IllegalArgumentException
MACFactory
,
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
true
if the given MAC matches the generated MAC of the given data and the given key using the given algorithm.
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; 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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
MACFactory
,
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
IllegalArgumentException
SignatureSignerFactory
,
SignatureSigner
,
EncodedSignature
public static boolean verify(byte[] data, int dataOffset, int dataLength, PublicKey key, String encodingAlgorithm, byte[] encodedSignature, int encodedSignatureOffset) throws NoSuchAlgorithmException, CryptoException, IllegalArgumentException
true
if the given signature verifies with the given public key on the given data, using the given algorithm.
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.
NoSuchAlgorithmException
CryptoException
IllegalArgumentException
SignatureDecoder
,
DecodedSignature
,
SignatureVerifier
public static byte[] getPRNG(byte[] seed, int seedOffset, int seedLength, int outputLength)
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
.
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
public static byte[] getPRNG(byte[] seed, int seedOffset, int seedLength, int outputLength, int prngType)
Supported values for prngType
are:
Crypto.PRNG_TYPE_FIPS186
Crypto.PRNG_TYPE_AES_CTR_DRBG
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.
IllegalArgumentException
- If an invalid prngType
is specified.AESCTRDRBGPseudoRandomSource
,
FIPS186PseudoRandomSource
,
RandomSource
,
Random
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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