CryptoUtils

public struct CryptoUtils

Various utility functions for conversions

  • Converts a string of hexadecimal digits to a byte array.

    Declaration

    Swift

    public static func byteArray(fromHex string: String) -> [UInt8]

    Parameters

    string

    The hex string (must contain an even number of digits)

    Return Value

    A byte array or [] if the input is not valid hexadecimal

  • Converts a UTF-8 String to a byte array.

    Declaration

    Swift

    public static func byteArray(from string: String) -> [UInt8]

    Parameters

    string

    the string

    Return Value

    A byte array

  • Converts a string of hexadecimal digits to an NSData object.

    Declaration

    Swift

    public static func data(fromHex string: String) -> NSData

    Parameters

    string

    The hex string (must contain an even number of digits)

    Return Value

    An NSData object

  • Converts a string of hexadecimal digits to an Data object.

    Declaration

    Swift

    public static func data(fromHex string: String) -> Data

    Parameters

    string

    The hex string (must contain an even number of digits)

    Return Value

    An Data object

  • Converts a byte array to an NSData object.

    Declaration

    Swift

    public static func data(from byteArray: [UInt8]) -> NSData

    Parameters

    byteArray

    The byte array

    Return Value

    An NSData object

  • Converts a byte array to an Data object.

    Declaration

    Swift

    public static func data(from byteArray: [UInt8]) -> Data

    Parameters

    byteArray

    The byte array

    Return Value

    An Data object

  • Converts a byte array to a string of hexadecimal digits.

    Declaration

    Swift

    public static func hexString(from byteArray: [UInt8], uppercase: Bool = false) -> String

    Parameters

    uppercase

    True to use uppercase for letter digits, lowercase otherwise

    Return Value

    A String

  • Converts a Swift array to an NSString object.

    Declaration

    Swift

    public static func hexNSString(from byteArray: [UInt8], uppercase: Bool = false) -> NSString

    Parameters

    uppercase

    True to use uppercase for letter digits, lowercase otherwise

    Return Value

    An NSString object

  • Converts a byte array to a String containing a comma separated list of bytes. This is used to generate test data programmatically.

    Declaration

    Swift

    public static func hexList(from byteArray: [UInt8]) -> String

    Parameters

    byteArray

    The byte array

    Return Value

    A String

  • Zero pads a byte array such that it is an integral number of blockSizeinBytes long.

    Declaration

    Swift

    public static func zeroPad(byteArray: [UInt8], blockSize: Int) -> [UInt8]

    Parameters

    blockSizeInBytes

    The block size in bytes.

    Return Value

    A Swift string

  • Zero pads a String (after UTF8 conversion) such that it is an integral number of blockSizeinBytes long.

    Declaration

    Swift

    public static func zeroPad(string: String, blockSize: Int) -> [UInt8]

    Parameters

    blockSizeInBytes

    The block size in bytes

    Return Value

    A byte array