TKCryptoEngine
@protocol TKCryptoEngine
Defines a set of methods that deal with crypto, key generation, method signing, etc.
-
Generates a key-pair of the specified level. If the key with the specified level already exists, it is replaced. Old key is still kept around in the Token Cloud because it could be used for signature verification later.
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-pair of the specified level. If the key with the specified level already exists, it is replaced. Old key is still kept around in the Token Cloud because it could be used for signature verification later.
Declaration
Objective-C
- (Key *)generateKey:(id)level withExpiration:(NSNumber *)expiresAtMs;
Swift
func generateKey(_ level: Any!, withExpiration expiresAtMs: NSNumber!) -> Key!
Parameters
level
key level
expiresAtMs
expiration date of the key in milliseconds
Return Value
the newly created key pair information
-
Gets a key-pair of the specified level. If the key with the specified level does not exist, return nil.
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 the data with the identified by the supplied key id.
Declaration
Objective-C
- (TKSignature *)signData:(NSData *)data usingKeyLevel:(id)keyLevel reason:(NSString *)reason onError:(OnError)onError;
Swift
func sign(_ data: Data!, usingKeyLevel keyLevel: Any!, reason: String!, onError: @escaping OnError) -> TKSignature!
Parameters
data
payload to sign
keyLevel
level of the 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
payload signature
-
Verifies the payload signature.
Declaration
Objective-C
- (_Bool)verifySignature:(NSString *)signature forData:(NSData *)data usingKeyId:(NSString *)keyId;
Swift
func verifySignature(_ signature: String!, for data: Data!, usingKeyId keyId: String!) -> Bool
Parameters
signature
signature
data
payload to verify the signature for.
keyId
key id
Return Value
true if successful