StreamCryptor
public class StreamCryptor
Encrypts or decrypts return results as they become available.
Use for large files or network streams.
For small, in-memory buffers Cryptor may be easier to use.
-
Enumerates Cryptor operations
See moreDeclaration
Swift
public enum Operation
-
Enumerates available algorithms
See moreDeclaration
Swift
public enum Algorithm
-
Maps CommonCryptoOptions onto a Swift struct.
See moreDeclaration
Swift
public struct Options : OptionSetType, BooleanType
-
The status code resulting from the last method call to this Cryptor. Used to get additional information when optional chaining collapes.
Declaration
Swift
public var status : Status = .Success
-
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)
-
Add the contents of an Objective-C NSData buffer to the current encryption/decryption operation.
Declaration
Swift
public func update(dataIn: NSData, inout byteArrayOut: [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
public func update(byteArrayIn: [UInt8], inout byteArrayOut: [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
public func update(stringIn: String, inout byteArrayOut: [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
public func final(inout byteArrayOut: [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: UnsafePointer<Void>, keyByteCount: Int, ivBuffer: UnsafePointer<Void>)
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 func update(bufferIn: UnsafePointer<Void>, byteCountIn: Int, bufferOut: UnsafeMutablePointer<Void>, byteCapacityOut : Int, inout byteCountOut : 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
public func final(bufferOut: UnsafeMutablePointer<Void>, byteCapacityOut : Int, inout byteCountOut : 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
public 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.