# Modules.Crypto.Cryptor
The Cryptor object provides access to a number of symmetric encryption algorithms. Symmetric encryption algorithms come in two "flavors" - block ciphers, and stream ciphers. Block ciphers process data (while both encrypting and decrypting) in discrete chunks of data called blocks; stream ciphers operate on arbitrary sized data.
# Overview
The Cryptor object provides access to both block ciphers and stream ciphers with the same API; however some options are available for block ciphers that do not apply to stream ciphers. The Android version of this module only exposes block ciphers.
The general operation of a Cryptor is:
- Initialize it with raw key data and other optional fields with
crypto.createCryptor()
- Process input data via one or more calls to
cryptor.update()
- Obtain possible remaining output data with
cryptor.final()
- The cryptor object is disposed of by setting the
cryptor
variable tonull
. The cryptor object can be reused (with the same key data as provided tocrypto.createCryptor()
) by callingcryptor.reset()
orcryptor.release()
.
Alternatively, cryptor.encrypt()
and cryptor.decrypt()
methods are provided for a stateless, one-shot encrypt or decrypt operation.
# Properties
# apiName READONLY
The name of the API that this proxy corresponds to.
The value of this property is the fully qualified name of the API. For example, Titanium.UI.Button
returns Ti.UI.Button
.
# lifecycleContainer
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.
# Methods
# applyProperties
Applies the properties to the proxy.
Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.
Parameters
Name | Type | Description |
---|---|---|
props | Dictionary | A dictionary of properties to apply. |
Returns
- Type
- void
# decrypt
Stateless, one-shot decryption operation.
Parameters
Name | Type | Description |
---|---|---|
dataIn | Titanium.Buffer | The Titanium.Buffer object containing the data to decrypt |
dataInLength | Number | The number of bytes in the dataIn buffer to decrypt. If this argument is not provided or is < 0, then the length of the dataIn buffer will be used. |
dataOut | Titanium.Buffer | The Titanium.Buffer object to receive the decrypted data. If this argument is not provided, then the dataIn buffer will be used.
|
dataOutLength | Number | The number of bytes available in the dataOut buffer. If this argument is not provided or is < 0, then the length of the dataOut buffer will be used. |
Returns
Returns the number of bytes decrypted into the dataOut buffer. If an error occurred, then the return value will be less than zero and will be one of the following values:
- STATUS_ERROR
- STATUS_PARAMERROR
- STATUS_BUFFERTOOSMALL
- STATUS_MEMORYFAILURE
- STATUS_ALIGNMENTERROR
- STATUS_DECODEERROR
- STATUS_UNIMPLEMENTED
- Type
- Number
# encrypt
Stateless, one-shot encryption operation.
Parameters
Name | Type | Description |
---|---|---|
dataIn | Titanium.Buffer | The Titanium.Buffer object containing the data to encrypt |
dataInLength | Number | The number of bytes in the dataIn buffer to encrypt. If this argument is not provided or is < 0, then the length of the dataIn buffer will be used. |
dataOut | Titanium.Buffer | The Titanium.Buffer object to receive the encrypted data. If this argument is not provided, then the dataIn buffer will be used.
|
dataOutLength | Number | The number of bytes available in the dataOut buffer. If this argument is not provided or is < 0, then the length of the dataOut buffer will be used. |
Returns
Returns the number of bytes encrypted into the dataOut buffer. If an error occurred, then the return value will be less than zero and will be one of the following values:
- STATUS_ERROR
- STATUS_PARAMERROR
- STATUS_BUFFERTOOSMALL
- STATUS_MEMORYFAILURE
- STATUS_ALIGNMENTERROR
- STATUS_DECODEERROR
- STATUS_UNIMPLEMENTED
- Type
- Number
# finish
Finishes encryption and decryption operations and obtains the final data output.
Parameters
Name | Type | Description |
---|---|---|
dataOut | Titanium.Buffer | The Titanium.Buffer object to receive the output data. If this argument is not provided, then the dataIn buffer will be used.
|
dataOutLength | Number | The number of bytes available in the dataOut buffer. If this argument is not provided or is < 0, then the length of the dataOut buffer will be used. |
Returns
Returns the number of bytes moved into the dataOut buffer. If an error occurred, then the return value will be less than zero and will be one of the following values:
- STATUS_ERROR
- STATUS_PARAMERROR
- STATUS_BUFFERTOOSMALL
- STATUS_MEMORYFAILURE
- STATUS_ALIGNMENTERROR
- STATUS_DECODEERROR
- STATUS_UNIMPLEMENTED
- Type
- Number
# getOutputLength
getOutputLength is used to determine the output buffer size required to process a given input size.
Parameters
Name | Type | Description |
---|---|---|
dataInLength | Number | The number of bytes for the operation |
final | Boolean |
Returns
Returns the number of bytes required for the output buffer
- Type
- Number
# release
release will dispose of the internal cryptor data
Returns
Returns one of the status constants:
- STATUS_SUCCESS
- STATUS_ERROR
- STATUS_PARAMERROR
- STATUS_BUFFERTOOSMALL
- STATUS_MEMORYFAILURE
- STATUS_ALIGNMENTERROR
- STATUS_DECODEERROR
- STATUS_UNIMPLEMENTED
- Type
- Number
# reset
reset reinitializes an existing cryptor object with a (possibly) new initialization vector.
Parameters
Name | Type | Description |
---|---|---|
initializationVector | Titanium.Buffer | The Titanium.Buffer object containing the initialization vector. |
Returns
Returns one of the status constants:
- STATUS_SUCCESS
- STATUS_ERROR
- STATUS_PARAMERROR
- STATUS_BUFFERTOOSMALL
- STATUS_MEMORYFAILURE
- STATUS_ALIGNMENTERROR
- STATUS_DECODEERROR
- STATUS_UNIMPLEMENTED
- Type
- Number
# update
update is used to encrypt or decrypt data. This method can be called multiple times. The caller does not need to align input data lengths to block sizes; input is buffered as necessary for block ciphers.
Parameters
Name | Type | Description |
---|---|---|
dataIn | Titanium.Buffer | The Titanium.Buffer object containing the data to decrypt |
dataInLength | Number | The number of bytes in the dataIn buffer to process. If this argument is not provided or is < 0, then the length of the dataIn buffer will be used. |
dataOut | Titanium.Buffer | The Titanium.Buffer object to receive the output data. If this argument is not provided, then the dataIn buffer will be used.
|
dataOutLength | Number | The number of bytes available in the dataOut buffer. If this argument is not provided or is < 0, then the length of the dataOut buffer will be used. |
Returns
Returns the number of bytes moved into the dataOut buffer. If an error occurred, then the return value will be less than zero and will be one of the following values:
- STATUS_ERROR
- STATUS_PARAMERROR
- STATUS_BUFFERTOOSMALL
- STATUS_MEMORYFAILURE
- STATUS_ALIGNMENTERROR
- STATUS_DECODEERROR
- STATUS_UNIMPLEMENTED
- Type
- Number