TKCrypto

@interface TKCrypto : NSObject

An abstract class that defines a set of methods that deal with crypto, key generation, method signing, etc. There are two abstract methods that need to be implemented in the derived classes signData and verifySignature:forData.

  • Undocumented

    Declaration

    Objective-C

    - (id)initWithEngine:(id<TKCryptoEngine>)engine;
  • Generates a set of keys to be used by a given member.

    Declaration

    Objective-C

    - (NSArray<Key *> *)generateKeys;

    Swift

    func generateKeys() -> [Key]!

    Return Value

    the newly created key pair information

  • Generates a key of the given level.

    Declaration

    Objective-C

    - (Key *)generateKey:(id)level;

    Swift

    func generateKey(_ level: Any!) -> Key!

    Parameters

    level

    key level

    Return Value

    the newly created key pair information

  • Generates a key of the given level with an expiration date

    Declaration

    Objective-C

    - (Key *)generateKey:(id)level withExpiration:(NSNumber *)expiresAtMs;

    Swift

    func generateKey(_ level: Any!, withExpiration expiresAtMs: NSNumber!) -> Key!

    Parameters

    level

    key level

    expiresAtMs

    the expiration date of the key in milliseconds.

    Return Value

    the newly created key pair information

  • Gets a set of key-pair information to be used by a given member.

    Declaration

    Objective-C

    - (NSArray<Key *> *)getKeyInfos:(NSString *)reason onError:(OnError)onError;

    Swift

    func getKeyInfos(_ reason: String!, onError: @escaping OnError) -> [Key]!

    Parameters

    reason

    the reason to get the key-pair

    onError

    callback to invoke on key-pair not found

    Return Value

    the key-pairs information

  • Gets a key of the given level.

    Declaration

    Objective-C

    - (Key *)getKeyInfo:(id)level
                 reason:(NSString *)reason
                onError:(OnError)onError;

    Swift

    func getKeyInfo(_ level: Any!, reason: String!, onError: @escaping OnError) -> Key!

    Parameters

    level

    key level

    reason

    the reason to get the key-pair

    onError

    callback to invoke on key-pair not found

    Return Value

    the key-pair information

  • Signs a message with the secret key specified by the supplied type.

    Declaration

    Objective-C

    - (TKSignature *)sign:(id)message
                 usingKey:(id)keyLevel
                   reason:(NSString *)reason
                  onError:(OnError)onError;

    Swift

    func sign(_ message: Any!, usingKey keyLevel: Any!, reason: String!, onError: @escaping OnError) -> TKSignature!

    Parameters

    message

    message to sign

    keyLevel

    key to use

    reason

    the reason the data is being signed

    onError

    callback to invoke on errors or user not authorizing the signature

    Return Value

    signed message, Base64 encoded

  • Signs a token with the secret key specified by the supplied type.

    Declaration

    Objective-C

    - (TKSignature *)sign:(Token *)token
                   action:(id)action
                 usingKey:(id)keyLevel
                   reason:(NSString *)reason
                  onError:(OnError)onError;

    Swift

    func sign(_ token: Token!, action: Any!, usingKey keyLevel: Any!, reason: String!, onError: @escaping OnError) -> TKSignature!

    Parameters

    token

    token to sign

    action

    action being signed on

    keyLevel

    key to use

    reason

    the reason the data is being signed

    onError

    callback to invoke on errors or user not authorizing the signature

    Return Value

    signed message, Base64 encoded

  • Signs a token payload with the secret key specified by the supplied type.

    Declaration

    Objective-C

    - (TKSignature *)signPayload:(TokenPayload *)tokenPayload
                          action:(id)action
                        usingKey:(id)keyLevel
                          reason:(NSString *)reason
                         onError:(OnError)onError;

    Swift

    func sign(_ tokenPayload: TokenPayload!, action: Any!, usingKey keyLevel: Any!, reason: String!, onError: @escaping OnError) -> TKSignature!

    Parameters

    tokenPayload

    token payload to sign

    action

    action being signed on

    keyLevel

    key to use

    reason

    the reason the data is being signed

    onError

    callback to invoke on errors or user not authorizing the signature

    Return Value

    signed message, Base64 encoded

  • Verifies a message signature.

    Declaration

    Objective-C

    - (_Bool)verifySignature:(NSString *)signature
                  forMessage:(id)message
                  usingKeyId:(NSString *)keyId;

    Swift

    func verifySignature(_ signature: String!, forMessage message: Any!, usingKeyId keyId: String!) -> Bool

    Parameters

    signature

    signature to verify

    message

    message to verify the signature for

    keyId

    key to use

    Return Value

    true if signature verifies

  • Verifies a token signature.

    Declaration

    Objective-C

    - (_Bool)verifySignature:(NSString *)signature
                    forToken:(Token *)token
                      action:(id)action
                  usingKeyId:(NSString *)keyId;

    Swift

    func verifySignature(_ signature: String!, for token: Token!, action: Any!, usingKeyId keyId: String!) -> Bool

    Parameters

    signature

    signature to verify

    token

    token to verify the signature for

    action

    action to verify the signature for

    keyId

    key to use

    Return Value

    true if signature verifies