Key¶
- public abstract class Key extends TokenObject¶
Abstract class describes a key object. Inherits from
TokenObject
.API Changes (since 6.23.44.2)
The mobile SDK API has evolved to support different key types:
PrivateKey
andPublicKey
are now abstract classes.Subclasses:
Methods specific to a particular key type have been moved into these concrete classes. For example:
PrivateKeyRSA.getModulus()
→ only available for RSA KeysPublicKeyEC.getW()
→ only available forPublicKeyEC
This change introduces some backward compatibility issues: to use these methods, you must cast the key to the appropriate class.
Example
PrivateKey privateKey; if (privateKey instanceof PrivateKeyRSA) { PrivateKeyRSA rsaPrivateKey = (PrivateKeyRSA) privateKey; BigInteger modulus = rsaPrivateKey.getModulus(); }
On the other hand, methods common to all private keys (
PrivateKey.sign()
,PrivateKey.decrypt()
,PrivateKey.hashAndSign()
,PrivateKey.getPssParameters()
,PrivateKey.isPartialHash()
) remain defined inPrivateKey
. Their usage has not changed.
Methods¶
getAlgorithmName¶
getKeyLength¶
- public int getKeyLength()¶
Gets the key length, in bits.
- Returns:
the key length.