SFSDKCryptoUtils Class Reference

Inherits from NSObject
Declared in SFSDKCryptoUtils.h

Overview

Various utility methods that support cryptographic operations.

+ randomByteDataWithLength:

Creates a random string of bytes (based on arc4random() generation) and returns them as an NSData object.

+ (NSData *)randomByteDataWithLength:(NSUInteger)lengthInBytes

Parameters

lengthInBytes

Number of bytes to generate.

Return Value

NSData object containing a string of random bytes.

Declared In

SFSDKCryptoUtils.h

+ pbkdf2DerivedKey:

Creates a PBKDF2 derived key from an input key string. Uses default values for the random-generated salt data and its length, the number of derivation rounds, and the derived key length.

+ (nullable NSData *)pbkdf2DerivedKey:(NSString *)stringToHash

Parameters

stringToHash

Plain-text string used to generate the key.

Return Value

The derived key.

Declared In

SFSDKCryptoUtils.h

+ pbkdf2DerivedKey:salt:derivationRounds:keyLength:

Creates a PBKDF2-derived key from an input key string, a salt, number of derivation rounds, and the given derived key length.

+ (nullable NSData *)pbkdf2DerivedKey:(NSString *)stringToHash salt:(NSData *)salt derivationRounds:(NSUInteger)numDerivationRounds keyLength:(NSUInteger)derivedKeyLength

Parameters

stringToHash

Base string to use for the derived key.

salt

Salt to append to the string.

numDerivationRounds

Number of derivation rounds used to generate the key.

derivedKeyLength

Requested derived key length.

Return Value

The derived key.

Declared In

SFSDKCryptoUtils.h

+ aes128EncryptData:withKey:iv:

Encrypt the given data using the AES-128 algorithm.

+ (nullable NSData *)aes128EncryptData:(NSData *)data withKey:(NSData *)key iv:(NSData *)iv

Parameters

data

Data to encrypt.

key

Key used to encrypt the data.

iv

Initialization vector data used for the encryption.

Return Value

NSData object containing the encrypted data, or nil if encryption failed.

Declared In

SFSDKCryptoUtils.h

+ aes128DecryptData:withKey:iv:

Decrypt the given data using the AES-128 algorithm.

+ (nullable NSData *)aes128DecryptData:(NSData *)data withKey:(NSData *)key iv:(NSData *)iv

Parameters

data

Data to decrypt.

key

Key used to decrypt the data.

iv

Initialization vector data used for the decryption.

Return Value

NSData object containing the decrypted data, or nil if decryption failed.

Declared In

SFSDKCryptoUtils.h

+ aes256EncryptData:withKey:iv:

Encrypt the given data using the AES-256 algorithm.

+ (nullable NSData *)aes256EncryptData:(NSData *)data withKey:(NSData *)key iv:(NSData *)iv

Parameters

data

Data to encrypt.

key

Key used to encrypt the data.

iv

Initialization vector data used for the encryption.

Return Value

NSData object containing the encrypted data, or nil if encryption failed.

Declared In

SFSDKCryptoUtils.h

+ aes256DecryptData:withKey:iv:

Decrypt the given data using the AES-256 algorithm.

+ (nullable NSData *)aes256DecryptData:(NSData *)data withKey:(NSData *)key iv:(NSData *)iv

Parameters

data

Data to decrypt.

key

Key used to decrypt the data.

iv

Initialization vector data used for the decryption.

Return Value

NSData object containing the decrypted data, or nil if decryption failed.

Declared In

SFSDKCryptoUtils.h

+ createRSAKeyPairWithName:keyLength:accessibleAttribute:

Create asymmetric keys (public/private key pairs) using RSA algorithm with given key name and length.

+ (void)createRSAKeyPairWithName:(NSString *)keyName keyLength:(NSUInteger)length accessibleAttribute:(CFTypeRef)accessibleAttribute

Parameters

keyName

Name of key.

length

Length of key.

Declared In

SFSDKCryptoUtils.h

+ getRSAPublicKeyStringWithName:keyLength:

Retrieve an RSA public key as NSString with given key name and length.

+ (nullable NSString *)getRSAPublicKeyStringWithName:(NSString *)keyName keyLength:(NSUInteger)length

Parameters

keyName

Name of key.

length

Length of key.

Return Value

Key string, or nil if no matching key is found.

Declared In

SFSDKCryptoUtils.h

+ getRSAPrivateKeyDataWithName:keyLength:

Retrieve an RSA private key as NSData with given key name and length.

+ (nullable NSData *)getRSAPrivateKeyDataWithName:(NSString *)keyName keyLength:(NSUInteger)length

Parameters

keyName

Name of key.

length

Length of key.

Return Value

NSData object containing the key data, or nil if no matching key is found.

Declared In

SFSDKCryptoUtils.h

+ getRSAPublicKeyRefWithName:keyLength:

Get RSA public SecKeyRef with given key name and length.

+ (nullable SecKeyRef)getRSAPublicKeyRefWithName:(NSString *)keyName keyLength:(NSUInteger)length

Parameters

keyName

Name of key.

length

Length of key.

Return Value

SecKeyRef object, or nil if no matching key is found.

Declared In

SFSDKCryptoUtils.h

+ getRSAPrivateKeyRefWithName:keyLength:

Get RSA private SecKeyRef with given key name and length.

+ (nullable SecKeyRef)getRSAPrivateKeyRefWithName:(NSString *)keyName keyLength:(NSUInteger)length

Parameters

keyName

Name of key.

length

Length of key.

Return Value

SecKeyRef object, or nil if no matching key is found.

Declared In

SFSDKCryptoUtils.h

+ encryptUsingRSAforData:withKeyRef:

Encrypt data with given SecKeyRef using the RSA pkcs1 algorithm.

+ (nullable NSData *)encryptUsingRSAforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef

Parameters

data

Data to encrypt

keyRef

Keyref used in encryption

Return Value

NSData object containing the encrypted Data, or nil if encryption failed.

Declared In

SFSDKCryptoUtils.h

+ decryptUsingRSAforData:withKeyRef:

Decrypt data with given SecKeyRef using the RSA pkcs1 algorithm.

+ (nullable NSData *)decryptUsingRSAforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef

Parameters

data

Data to decrypt

keyRef

Keyref used in decryption

Return Value

NSData object containing the decrypted Data, or nil if decryption failed.

Declared In

SFSDKCryptoUtils.h

+ isSecureEnclaveAvailable

Check for availability of the secure enclave.

+ (BOOL)isSecureEnclaveAvailable

Return Value

YES if secure enclave is available.

Declared In

SFSDKCryptoUtils.h

+ createECKeyPairWithName:accessibleAttribute:useSecureEnclave:

Create asymmetric keys (public/private key pairs) using the EC algorithm with given key name.

+ (BOOL)createECKeyPairWithName:(NSString *)keyName accessibleAttribute:(CFTypeRef)accessibleAttribute useSecureEnclave:(BOOL)useSecureEnclave

Parameters

keyName

Name of key.

Return Value

YES if successful.

Declared In

SFSDKCryptoUtils.h

+ deleteECKeyPairWithName:

Delete an EC key pair created with createECKeyPairWithName:accessibleAttribute:useSecureEnclase:.

+ (BOOL)deleteECKeyPairWithName:(NSString *)keyName

Parameters

keyName

Name of key.

Return Value

YES if successful.

Declared In

SFSDKCryptoUtils.h

+ getECPublicKeyRefWithName:

Get EC public SecKeyRef with the given key name.

+ (nullable SecKeyRef)getECPublicKeyRefWithName:(NSString *)keyName

Parameters

keyName

Name of key.

Return Value

SecKeyRef object, or nil if no matching key is found.

Declared In

SFSDKCryptoUtils.h

+ getECPrivateKeyRefWithName:

Get EC private SecKeyRef with the given key name.

+ (nullable SecKeyRef)getECPrivateKeyRefWithName:(NSString *)keyName

Parameters

keyName

Name of key.

Return Value

SecKeyRef object, or nil if no matching key is found.

Declared In

SFSDKCryptoUtils.h

+ encryptUsingECforData:withKeyRef:

Encrypt data with the given SecKeyRef using the EC algorithm.

+ (nullable NSData *)encryptUsingECforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef

Parameters

data

Data to encrypt.

keyRef

Keyref used in encryption.

Return Value

NSData object containing the encrypted data, or nil if encryption failed.

Declared In

SFSDKCryptoUtils.h

+ decryptUsingECforData:withKeyRef:

Decrypt data with the given SecKeyRef using the EC algorithm.

+ (nullable NSData *)decryptUsingECforData:(NSData *)data withKeyRef:(SecKeyRef)keyRef

Parameters

data

Data to decrypt.

keyRef

Keyref used in decryption.

Return Value

NSData object containing the decrypted data, or nil if decryption failed.

Declared In

SFSDKCryptoUtils.h