Key

public class Key : TokenObject

Class that describes a key object. Inherits from TokenObject.

API Changes (since 6.23.45.0) The mobile SDK API has evolved to support different key types: PrivateKey and PublicKey are no more final classes.

Subclasses: PrivateKeyRSA and PublicKeyRSA. PrivateKeyEC and PublicKeyEC. Methods specific to a particular key type have been moved into these concrete classes. For example: getModulus → only available for RSA Keys. getECParams → only available for EC keys. This change introduces some backward compatibility issues: to use these methods, you must cast the key to the appropriate class, see the example. On the other hand, methods common to all private keys sign, decrypt, hashAndSign, isPartialHash remain defined in PrivateKey. Their usage has not changed.

Example:

 let key : Key
 if let publicKeyEC = key as? PublicKeyEC {
        publicKeyEC.getECParams { ecParams, error in
            if let error = error {
                print("Error: \(error.localizedDescription)")
            } else if let ecParams = ecParams {
                print("EC Params : \(ecParams)")
            } else {
                print("No data received")
            }
        }
 }
  • Returns the algorithm of the key.

    See also

    KeyAlgorithm

    Declaration

    Swift

    public func getAlgorithm() -> KeyAlgorithm

    Return Value

    The algorithm of the key.

  • Returns the key length, in bits.

    Declaration

    Swift

    public func getKeyLength() -> Int

    Return Value

    The length of the key.