|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--net.rim.device.api.crypto.encoder.PublicKeyDecoder
Allows the developer to decode public keys using a variety of supported encoding algorithms.
The details of creating and using the appropriate algorithm are managed by PublicKeyDecoder
and are completely transparent to the developer.
Encoding a Public Key
Encoding a public key simply involves calling the public static encode() method
with the desired public key. As the following code illustrates, encoding an RSA public key using the
X509 algorithm is straightforward:
RSAPublicKey key = new RSAPublicKey( ... );
EncodedKey encodedKey = PublicKeyEncoder.encode( key, "X509", false );
Of course, the RSA public key must be properly created and initialized.
Decoding a Public Key
Decoding a public key is similar to encoding one. Simply call the public static decode()
method with the encoded key data:
byte[] encodedKeyData = ...;
PublicKey decodedKey = PublicKeyEncoder.decode( encodedKeyData, "X509" );
This code assumes that encodedKey contains a properly encoded public key.
Currently, RIM provides the following public key encoding algorithms, which can be accessed with the specifed string :
Microsoft Crypto API Use the encoding string "MSCAPI". X509 encoding Use the encoding string "X509". WTLS encoding Use the encoding string "WTLS".
Supported Encoding Algorithms
The MSCAPI encoding can be found in MSDN. The X509 encoding is defined in RFC 2459. Finally, the WTLS encoding is found in WAP-199-WTLS from Feb 2000.
A complete list of the key encoding algorithms supported by the RIM crypto API can be found here.
If a developer wishes to implement a key encoding algorithm not found in this list, the PublicKeyEncoder class can be extended.
This information can be found here.
| Constructor Summary |
| Method Summary | ||
|
static PublicKey |
decode(byte[] encodedKey,
String encodingAlgorithm)
Takes in the given encoded key and returns the decoded public key. |
|
static PublicKey |
decode(byte[] encodedKey,
String encodingAlgorithm,
CryptoSystem cryptoSystem,
String keyAlgorithm)
Decodes an encoded public key. |
|
static PublicKey |
decode(InputStream encodedKey,
String encodingAlgorithm)
Takes in the given encoded key and returns the decoded public key. |
|
static PublicKey |
decode(InputStream encodedKey,
String encodingAlgorithm,
CryptoSystem cryptoSystem,
String keyAlgorithm)
Decodes an encoded public key. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
| Method Detail |
public static PublicKey decode(InputStream encodedKey, String encodingAlgorithm, CryptoSystem cryptoSystem, String keyAlgorithm) throws NoSuchAlgorithmException, InvalidKeyEncodingException, InvalidKeyException, InvalidCryptoSystemException, UnsupportedCryptoSystemException, CryptoTokenException, CryptoUnsupportedOperationException
encodedKey - An InputStream containing the key encoding.encodingAlgorithm - The encoding algorithm to use to decode, such as "X509".cryptoSystem - The crypto system to retrieve parameter information from, if necessary.keyAlgorithm - The type of key.NoSuchAlgorithmException - Thrown if the specified algorithm is
invalid.InvalidKeyEncodingException - Thrown if the key is improperly
formatted.InvalidKeyException - Thrown if the specified key is invalid.InvalidCryptoSystemException - Thrown if the specified crypto
system is invalid.UnsupportedCryptoSystemException - Thrown if the specified crypto
system is unsupported.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 PublicKey decode(byte[] encodedKey, String encodingAlgorithm, CryptoSystem cryptoSystem, String keyAlgorithm) throws NoSuchAlgorithmException, InvalidKeyEncodingException, InvalidKeyException, InvalidCryptoSystemException, UnsupportedCryptoSystemException, CryptoTokenException, CryptoUnsupportedOperationException
encodedKey - A byte array containing the key encoding.encodingAlgorithm - The encoding algorithm to use to decode, such as "X509".cryptoSystem - The crypto system to retrieve parameter information, if necessary.keyAlgorithm - The type of key.NoSuchAlgorithmException - Thrown if the specified algorithm is
invalid.InvalidKeyEncodingException - Thrown if the key is improperly
formatted.InvalidKeyException - Thrown if the specified key is invalid.InvalidCryptoSystemException - Thrown if the specified crypto
system is invalid.UnsupportedCryptoSystemException - Thrown if the specified crypto
system is unsupported.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 PublicKey decode(InputStream encodedKey, String encodingAlgorithm) throws NoSuchAlgorithmException, InvalidKeyEncodingException, InvalidKeyException, InvalidCryptoSystemException, UnsupportedCryptoSystemException, CryptoTokenException, CryptoUnsupportedOperationException
encodedKey - An input stream containing the encoding and other relevant information.encodingAlgorithm - The encoding algorithm to use to decode, such as "X509."NoSuchAlgorithmException - Thrown if the specified algorithm is
invalid.InvalidKeyEncodingException - Thrown if the key is improperly
formatted.InvalidKeyException - Thrown if the specified key is invalid.InvalidCryptoSystemException - Thrown if the specified crypto
system is invalid.UnsupportedCryptoSystemException - Thrown if the specified crypto
system is unsupported.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 PublicKey decode(byte[] encodedKey, String encodingAlgorithm) throws NoSuchAlgorithmException, InvalidKeyEncodingException, InvalidKeyException, InvalidCryptoSystemException, UnsupportedCryptoSystemException, CryptoTokenException, CryptoUnsupportedOperationException
encodedKey - A byte array containing the encoding and other relevant information.encodingAlgorithm - The encoding algorithm to use to decode, such as "X509."NoSuchAlgorithmException - Thrown if the specified algorithm is
invalid.InvalidKeyEncodingException - Thrown if the key is improperly
formatted.InvalidKeyException - Thrown if the specified key is invalid.InvalidCryptoSystemException - Thrown if the specified crypto
system is invalid.UnsupportedCryptoSystemException - Thrown if the specified crypto
system is unsupported.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.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2002 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.