|
|||||||||
| 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.PrivateKeyEncoder
Allows the developer to encode private keys using a variety of supported encoding algorithms.
The details of creating and using the appropriate algorithm are managed by PrivateKeyEncoder
and are completely transparent to the developer.
Encoding a Private Key
Encoding a private key involves calling the public static encode() method
with the desired private key. As the following code illustrates, encoding an RSA private key using the
X509 algorithm is straightforward:
RSAPrivateKey key = new RSAPrivateKey( ... );
EncodedKey encodedKey = PrivateKeyEncoder.encode( key, "PKCS8", false );
Of course, the RSA private key must be properly created and initialized.
Decoding a Private Key
Decoding a private key is similar to encoding one. Simply call the public static decode()
method with the encoded key data:
byte[] encodedKeyData = ...;
PrivateKey decodedKey = PrivateKeyEncoder.decode( encodedKeyData, "PKCS8" );
This code assumes that encodedKeyData contains a properly encoded private key.
Supported Encoding Algorithms
Please see here for a list of the RIM supplied encoding algorithms. Currently, RIM provides the following private key encoding algorithms, which can be accessed with the specifed string :
Microsoft Crypto API Use the encoding string "MSCAPI". PKCS8 encoding Use the encoding string "PKCS8".
The MSCAPI encoding can be found in MSDN. The PKCS8 encoding is found in the PKCS8 standard v1.2.
For algorithms not found in this list, a developer can implement additional private key encoding algorithms that can be integrated into the Crypto API. Please see the tutorial on Adding Encoders.
| Constructor Summary |
| Method Summary | ||
|
static EncodedKey |
encode(PrivateKey key)
Encodes a given key using the default PKCS8 encoding scheme. |
|
static EncodedKey |
encode(PrivateKey key,
String encodingAlgorithm)
Encodes a given key using the specified encoding scheme. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
| Method Detail |
public static EncodedKey encode(PrivateKey key) throws NoSuchAlgorithmException, CryptoTokenException, CryptoUnsupportedOperationException
The crypto system parameters are encoded.
key - The private 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(PrivateKey key, String encodingAlgorithm) throws NoSuchAlgorithmException, CryptoTokenException, CryptoUnsupportedOperationException
key - The private key to encode.encodingAlgorithm - A string representing the encoding Algorithm to use, eg "PKCS8".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.
|
|||||||||
| 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.