WLSecurityUtilsSwift
public class WLSecurityUtilsSwift
IBM Mobile First Platform Security Utils
-
Generates a key by using the PBKDF2 algorithm.
Throws
An error in case of failure.
Declaration
Swift
public static func generateKey(withPassword: String, andSalt: String, andIterations: Int) throws -> String
Parameters
withPassword
The password that is used to generate the key.
andSalt
The salt that is used to generate the key.
andIterations
The number of iterations that is passed to the key generation algorithm.
Return Value
The generated key.
-
Encrypts text with a key.
Throws
An error in case of failure.
Declaration
Swift
public static func encryptText(text: String, withKey: String) throws -> [AnyHashable : Any]
Parameters
text
The text to encrypt
withKey
The key used for encryption
Return Value
A Dictionary with the cipher text (ct), the IV (iv), the source (src) and the version (v).
-
Decrypts a dictionary that contains: src (source), v (version), ct (cipher text) and the iv (initialization vector).
Throws
An error in case of failure.
Declaration
Swift
public static func decrypt(withKey: String, andDictionary: [AnyHashable : Any]) throws -> String
Parameters
withKey
The key used for decryption
andDictionary
NSDictionary that is returned from encryptText:withKey:error:
Return Value
The decrypted text.
-
Generates a random string locally.
Declaration
Swift
public static func generateRandomString(withBytes: Int32) -> String
Parameters
withBytes
Number of bytes that is used to generate the random string
Return Value
The random string, nil if the operation failss
-
Gets a random string from the server.
Declaration
Swift
public static func getRandomStringFromServer(withBytes: Int32, timeout:Int32, onCompletion: @escaping (URLResponse?,Data?,Error?) -> Void)
Parameters
withBytes
Number of bytes that are used to generate the random string (maximum 64 bytes)
timeout
The time to wait for the network request to finish
onCompletion
Called when the request finished, the data field will have the random string (NSUTF8StringEncoding)
-
Encodes data to an NSString with Base64 encoding.
Declaration
Swift
public static func base64String(data: Data, length: Int) -> String
Parameters
data
Data
length
Length of the input
Return Value
Base64 encoded NSString
-
Reads Base64 encoded file and writes decoded output to output file
Declaration
Swift
public static func decodeBase64(withFiles: FileHandle, output: String)
Parameters
withFiles
Handle to input file; the caller is responsible for closing the file
output
Full string path to output file