StreamCryptor

open class StreamCryptor

Encrypts or decrypts return results as they become available.

Note

The underlying cipher may be a block or a stream cipher.

Use for large files or network streams.

For small, in-memory buffers Cryptor may be easier to use.

  • Creates a new StreamCryptor

    Declaration

    Swift

    public convenience init(operation: Operation, algorithm: Algorithm, options: Options, key: [UInt8], iv : [UInt8])

    Parameters

    operation

    the operation to perform see Operation (Encrypt, Decrypt)

    algorithm

    the algorithm to use see Algorithm (AES, DES, TripleDES, CAST, RC2, Blowfish)

    key

    a byte array containing key data

    iv

    a byte array containing initialization vector

  • Creates a new StreamCryptor

    Declaration

    Swift

    public convenience init(operation: Operation, algorithm: Algorithm, options: Options, key: String, iv : String)

    Parameters

    operation

    the operation to perform see Operation (Encrypt, Decrypt)

    algorithm

    the algorithm to use see Algorithm (AES, DES, TripleDES, CAST, RC2, Blowfish)

    key

    a string containing key data (will be interpreted as UTF8)

    iv

    a string containing initialization vector data (will be interpreted as UTF8)

  • Creates a new StreamCryptor

    Declaration

    Swift

    public convenience init(operation: Operation, algorithm: Algorithm, mode: Mode, padding: Padding, key: [UInt8], iv : [UInt8])

    Parameters

    operation

    the operation to perform see Operation (Encrypt, Decrypt)

    algorithm

    the algorithm to use see Algorithm (AES, DES, TripleDES, CAST, RC2, Blowfish)

    mode

    the mode used by algorithm see Mode (ECB, CBC, CFB, CTR, F8, LRW, OFB, XTS, RC4, CFB8)

    padding

    the padding to use. When using NoPadding: each block of UPDATE must be correct size

    key

    a byte array containing key data

    iv

    a byte array containing initialization vector

  • Creates a new StreamCryptor

    Declaration

    Swift

    public convenience init(operation: Operation, algorithm: Algorithm, mode: Mode, padding: Padding, key: String, iv: String)

    Parameters

    operation

    the operation to perform see Operation (Encrypt, Decrypt)

    algorithm

    the algorithm to use see Algorithm (AES, DES, TripleDES, CAST, RC2, Blowfish)

    mode

    the mode used by algorithm see Mode (ECB, CBC, CFB, CTR, F8, LRW, OFB, XTS, RC4, CFB8)

    padding

    the padding to use. When using NoPadding: each block of UPDATE must be correct size

    key

    a string containing key data (will be interpreted as UTF8)

    iv

    a string containing initialization vector data (will be interpreted as UTF8)

  • Add the contents of an Objective-C NSData buffer to the current encryption/decryption operation.

    Declaration

    Swift

    open func update(dataIn: Data, byteArrayOut: inout [UInt8]) -> (Int, Status)

    Parameters

    dataIn

    the input data

    byteArrayOut

    output data

    Return Value

    a tuple containing the number of output bytes produced and the status (see Status)

  • Add the contents of a Swift byte array to the current encryption/decryption operation.

    Declaration

    Swift

    open func update(byteArrayIn: [UInt8], byteArrayOut: inout [UInt8]) -> (Int, Status)

    Parameters

    byteArrayIn

    the input data

    byteArrayOut

    output data

    Return Value

    a tuple containing the number of output bytes produced and the status (see Status)

  • Add the contents of a string (interpreted as UTF8) to the current encryption/decryption operation.

    Declaration

    Swift

    open func update(stringIn: String, byteArrayOut: inout [UInt8]) -> (Int, Status)

    Parameters

    byteArrayIn

    the input data

    byteArrayOut

    output data

    Return Value

    a tuple containing the number of output bytes produced and the status (see Status)

  • Retrieves all remaining encrypted or decrypted data from this cryptor.

    :note: If the underlying algorithm is an block cipher and the padding option has not been specified and the cumulative input to the cryptor has not been an integral multiple of the block length this will fail with an alignment error.

    :note: This method updates the status property

    Declaration

    Swift

    open func final(byteArrayOut: inout [UInt8]) -> (Int, Status)

    Parameters

    byteArrayOut

    the output bffer

    Return Value

    a tuple containing the number of output bytes produced and the status (see Status)

  • Declaration

    Swift

    public init(operation: Operation, algorithm: Algorithm, options: Options, keyBuffer: UnsafeRawPointer,
            keyByteCount: Int, ivBuffer: UnsafeRawPointer)

    Parameters

    operation

    the operation to perform see Operation (Encrypt, Decrypt)

    algorithm

    the algorithm to use see Algorithm (AES, DES, TripleDES, CAST, RC2, Blowfish)

    keyBuffer

    pointer to key buffer

    keyByteCount

    number of bytes in the key

    ivBuffer

    initialization vector buffer

  • Declaration

    Swift

    public init(operation: Operation, algorithm: Algorithm, mode: Mode, padding: Padding, keyBuffer: UnsafeRawPointer, keyByteCount: Int, ivBuffer: UnsafeRawPointer)

    Parameters

    operation

    the operation to perform see Operation (Encrypt, Decrypt)

    algorithm

    the algorithm to use see Algorithm (AES, DES, TripleDES, CAST, RC2, Blowfish)

    mode

    the mode used by algorithm see Mode (ECB, CBC, CFB, CTR, F8, LRW, OFB, XTS, RC4, CFB8)

    padding

    the padding to use. When using NoPadding: each block of UPDATE must be correct size

    keyBuffer

    pointer to key buffer

    keyByteCount

    number of bytes in the key

    ivBuffer

    initialization vector buffer

  • Declaration

    Swift

    @discardableResult open func update(bufferIn: UnsafeRawPointer, byteCountIn: Int, bufferOut: UnsafeMutableRawPointer, byteCapacityOut: Int, byteCountOut: inout Int) -> Status

    Parameters

    bufferIn

    pointer to input buffer

    inByteCount

    number of bytes contained in input buffer

    bufferOut

    pointer to output buffer

    outByteCapacity

    capacity of the output buffer in bytes

    outByteCount

    on successful completion, the number of bytes written to the output buffer

    Return Value

  • Retrieves all remaining encrypted or decrypted data from this cryptor.

    :note: If the underlying algorithm is an block cipher and the padding option has not been specified and the cumulative input to the cryptor has not been an integral multiple of the block length this will fail with an alignment error.

    :note: This method updates the status property

    Declaration

    Swift

    @discardableResult open func final(bufferOut: UnsafeMutableRawPointer, byteCapacityOut: Int, byteCountOut: inout Int) -> Status

    Parameters

    bufferOut

    pointer to output buffer

    outByteCapacity

    capacity of the output buffer in bytes

    outByteCount

    on successful completion, the number of bytes written to the output buffer

  • Determines the number of bytes that wil be output by this Cryptor if inputBytes of additional data is input.

    Declaration

    Swift

    open func getOutputLength(inputByteCount: Int, isFinal: Bool = false) -> Int

    Parameters

    inputByteCount

    number of bytes that will be input.

    isFinal

    true if buffer to be input will be the last input buffer, false otherwise.