|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.rim.device.api.crypto.encoder.SymmetricKeyEncoder
public abstract class SymmetricKeyEncoder
Allows the developer to encode symmetric keys using a variety of supported encoding algorithms.
Once again, the details of creating and using the appropriate algorithm are managed by SymmetricKeyDecoder
and are completely transparent to the developer.
Encoding a Symmetric Key
Encoding a public key involves calling the public static encode()
method
with the desired symmetric key. As the following code illustrates, encoding a
is straightforward:
DESKey key = new DESKey( ... ); EncodedKey encodedKey = SymmetricKeyEncoder.encode( key, "scheme" );Of course, the DES key must be properly created and initialized.
Decoding a Symmetric Key
Decoding a symmetric key is similar to encoding one. Simply call the public static decode()
method with the encoded key:
byte[] encodedKeyData = ...; SymmetricKey decodedKey = SymmetricKeyDecoder.decode( encodedKey, "scheme" );This code assumes that
encodedKey
contains a properly encoded symmetric key.
Supported Encoding Algorithms
A complete list of the key encoding algorithms supported by the RIM crypto API can be found here. Currently, RIM provides the following symmetric key encoding algorithms, which can be accessed with the specifed string :
A RIM variant of PKCS8 Use the encoding string "PKCS8".
For algorithms not found in this list, a developer can implement additional symmetric key decoding algorithms that can be integrated into the Crypto API. Please see the tutorial on Adding Encoders.
Constructor Summary | ||
---|---|---|
|
protected |
SymmetricKeyEncoder()
Creates a new SymmetricKeyEncoder object. |
Method Summary | ||
---|---|---|
|
static EncodedKey |
encode(SymmetricKey key)
Encodes the given key using the default PKCS8 encoding scheme. |
|
static EncodedKey |
encode(SymmetricKey key,
String encodingAlgorithm)
Encodes a given key using the specified encoding scheme. |
|
protected abstract EncodedKey |
encodeKey(SymmetricKey key)
Encodes the passed in key in the proper format. |
|
protected static SymmetricKeyEncoder |
getEncoder(String encodingAlgorithm,
String keyAlgorithm)
Returns the class associated with the encoding algorithm and the key algorithm. |
|
protected abstract String |
getEncodingAlgorithm()
Returns the name of the encoding used, such as "PKCS8". |
|
protected abstract String[] |
getKeyAlgorithms()
Returns the name of the key that was encoded, such as ("DES", "HMAC"). |
|
static boolean |
register(SymmetricKeyEncoder encoder)
Registers the given encoder class with the API. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected SymmetricKeyEncoder()
SymmetricKeyEncoder
object.
This is the default constructor.
Method Detail |
---|
public static EncodedKey encode(SymmetricKey key) throws NoSuchAlgorithmException, CryptoTokenException, CryptoUnsupportedOperationException
key
- The symmetric key to encode.
EncodedKey
object containing the encoded key.
NoSuchAlgorithmException
- Thrown if the encoding algorithm cannot
be found.
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.public static EncodedKey encode(SymmetricKey key, String encodingAlgorithm) throws NoSuchAlgorithmException, CryptoTokenException, CryptoUnsupportedOperationException
key
- The symmetric key to encode.encodingAlgorithm
- A String representing the encoding Algorithm to use, eg "PKCS8".
EncodedKey
object containing the encoded key.
NoSuchAlgorithmException
- Thrown if the specified encoding
algorithm cannot be found.
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.protected abstract EncodedKey encodeKey(SymmetricKey key) throws NoSuchAlgorithmException, CryptoTokenException, CryptoUnsupportedOperationException
key
- A symmetric key to encode.
NoSuchAlgorithmException
- Thrown if the specified encoding
algorithm cannot be found.
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.public static boolean register(SymmetricKeyEncoder encoder) throws NoSuchAlgorithmException
encoder
- The symmetric key encoder to register.
NoSuchAlgorithmException
- Thrown if the specified encoding algorithm cannot be found.protected static SymmetricKeyEncoder getEncoder(String encodingAlgorithm, String keyAlgorithm) throws NoSuchAlgorithmException
encodingAlgorithm
- The encoding algorithm such as "PKCS8".keyAlgorithm
- The key type that was encoded, such as "DES".
NoSuchAlgorithmException
- Thrown if the encoding algorithm cannot be found.protected abstract String getEncodingAlgorithm()
protected abstract String[] getKeyAlgorithms()
|
|||||||||
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