Skip to content

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.

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:

  1. Initialize it with raw key data and other optional fields with crypto.createCryptor()
  2. Process input data via one or more calls to cryptor.update()
  3. Obtain possible remaining output data with cryptor.final()
  4. The cryptor object is disposed of by setting the cryptor variable to null. The cryptor object can be reused (with the same key data as provided to crypto.createCryptor()) by calling cryptor.reset() or cryptor.release().

Alternatively, cryptor.encrypt() and cryptor.decrypt() methods are provided for a stateless, one-shot encrypt or decrypt operation.

Extends: Titanium.Proxy · Since: 4.0.0, 4.0.0, 4.0.0 · Platforms: android, iphone, ipad

Properties #

algorithm#

Type: Number

Used in the encrypt, decrypt,
update and finish methods.

initializationVector#

Type: Titanium.Buffer

Used in the encrypt, decrypt,
update and finish methods.

key#

Type: Titanium.Buffer

Used in the encrypt, decrypt,
update and finish methods.

operation#

Type: Number

Used in the capture and parse methods
and the success event to specify accepted formats.

options#

Type: Number

Used in the encrypt, decrypt,
update and finish methods.

resizeBuffer#

Type: Boolean

Used in the encrypt, decrypt,
update and finish methods.
Indicates if the dataOut buffer should be resized to the size needed to hold the result of the operation.

Methods #

decrypt #

Stateless, one-shot decryption operation.

Parameters:
NameTypeSummaryOptional
dataInTitanium.BufferThe Titanium.Buffer object containing the data to decryptNo
dataInLengthNumberThe 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.Yes
dataOutTitanium.BufferThe Titanium.Buffer object to receive the decrypted data. If this argument is not provided, then the dataIn buffer will be used.
* If the resizeBuffer property is set to true, then the dataOut buffer will be resized to the size of the decrypted data
* If the resizeBuffer property is set to false, then ensure that the dataOut buffer is large enough to receive the decrypted data.
Yes
dataOutLengthNumberThe 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.Yes

Returns: Number — 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](Modules.Crypto.STATUS_ERROR) * [STATUS_PARAMERROR](Modules.Crypto.STATUS_PARAMERROR) * [STATUS_BUFFERTOOSMALL](Modules.Crypto.STATUS_BUFFERTOOSMALL) * [STATUS_MEMORYFAILURE](Modules.Crypto.STATUS_MEMORYFAILURE) * [STATUS_ALIGNMENTERROR](Modules.Crypto.STATUS_ALIGNMENTERROR) * [STATUS_DECODEERROR](Modules.Crypto.STATUS_DECODEERROR) * [STATUS_UNIMPLEMENTED](Modules.Crypto.STATUS_UNIMPLEMENTED)

encrypt #

Stateless, one-shot encryption operation.

Parameters:
NameTypeSummaryOptional
dataInTitanium.BufferThe Titanium.Buffer object containing the data to encryptNo
dataInLengthNumberThe 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.Yes
dataOutTitanium.BufferThe Titanium.Buffer object to receive the encrypted data. If this argument is not provided, then the dataIn buffer will be used.
* If the resizeBuffer property is set to true, then the dataOut buffer will be resized to the size of the encrypted data
* If the resizeBuffer property is set to false, then ensure that the dataOut buffer is large enough to receive the encrypted data.
Yes
dataOutLengthNumberThe 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.Yes

Returns: Number — 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](Modules.Crypto.STATUS_ERROR) * [STATUS_PARAMERROR](Modules.Crypto.STATUS_PARAMERROR) * [STATUS_BUFFERTOOSMALL](Modules.Crypto.STATUS_BUFFERTOOSMALL) * [STATUS_MEMORYFAILURE](Modules.Crypto.STATUS_MEMORYFAILURE) * [STATUS_ALIGNMENTERROR](Modules.Crypto.STATUS_ALIGNMENTERROR) * [STATUS_DECODEERROR](Modules.Crypto.STATUS_DECODEERROR) * [STATUS_UNIMPLEMENTED](Modules.Crypto.STATUS_UNIMPLEMENTED)

finish #

Finishes encryption and decryption operations and obtains the final data output.

Parameters:
NameTypeSummaryOptional
dataOutTitanium.BufferThe Titanium.Buffer object to receive the output data. If this argument is not provided, then the dataIn buffer will be used.
* If the resizeBuffer property is set to true, then the dataOut buffer will be resized to the size of the decrypted data
* If the resizeBuffer property is set to false, then ensure that the dataOut buffer is large enough to receive the decrypted data.
No
dataOutLengthNumberThe 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.Yes

Returns: Number — 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](Modules.Crypto.STATUS_ERROR) * [STATUS_PARAMERROR](Modules.Crypto.STATUS_PARAMERROR) * [STATUS_BUFFERTOOSMALL](Modules.Crypto.STATUS_BUFFERTOOSMALL) * [STATUS_MEMORYFAILURE](Modules.Crypto.STATUS_MEMORYFAILURE) * [STATUS_ALIGNMENTERROR](Modules.Crypto.STATUS_ALIGNMENTERROR) * [STATUS_DECODEERROR](Modules.Crypto.STATUS_DECODEERROR) * [STATUS_UNIMPLEMENTED](Modules.Crypto.STATUS_UNIMPLEMENTED)

getOutputLength #

getOutputLength is used to determine the output buffer size required to process a given input size.

Parameters:
NameTypeSummaryOptional
dataInLengthNumberThe number of bytes for the operationNo
finalBooleanIndicates if the calculation is for determining the output buffer size for a call to final
or update. Set to true for final and false for
update.
No

Returns: Number — Returns the number of bytes required for the output buffer

release #

release will dispose of the internal cryptor data

Returns: Number — Returns one of the status constants: * [STATUS_SUCCESS](Modules.Crypto.STATUS_SUCCESS) * [STATUS_ERROR](Modules.Crypto.STATUS_ERROR) * [STATUS_PARAMERROR](Modules.Crypto.STATUS_PARAMERROR) * [STATUS_BUFFERTOOSMALL](Modules.Crypto.STATUS_BUFFERTOOSMALL) * [STATUS_MEMORYFAILURE](Modules.Crypto.STATUS_MEMORYFAILURE) * [STATUS_ALIGNMENTERROR](Modules.Crypto.STATUS_ALIGNMENTERROR) * [STATUS_DECODEERROR](Modules.Crypto.STATUS_DECODEERROR) * [STATUS_UNIMPLEMENTED](Modules.Crypto.STATUS_UNIMPLEMENTED)

reset #

reset reinitializes an existing cryptor object with a (possibly) new initialization vector.

Parameters:
NameTypeSummaryOptional
initializationVectorTitanium.BufferThe Titanium.Buffer object containing the initialization vector.Yes

Returns: Number — Returns one of the status constants: * [STATUS_SUCCESS](Modules.Crypto.STATUS_SUCCESS) * [STATUS_ERROR](Modules.Crypto.STATUS_ERROR) * [STATUS_PARAMERROR](Modules.Crypto.STATUS_PARAMERROR) * [STATUS_BUFFERTOOSMALL](Modules.Crypto.STATUS_BUFFERTOOSMALL) * [STATUS_MEMORYFAILURE](Modules.Crypto.STATUS_MEMORYFAILURE) * [STATUS_ALIGNMENTERROR](Modules.Crypto.STATUS_ALIGNMENTERROR) * [STATUS_DECODEERROR](Modules.Crypto.STATUS_DECODEERROR) * [STATUS_UNIMPLEMENTED](Modules.Crypto.STATUS_UNIMPLEMENTED)

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:
NameTypeSummaryOptional
dataInTitanium.BufferThe Titanium.Buffer object containing the data to decryptNo
dataInLengthNumberThe 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.Yes
dataOutTitanium.BufferThe Titanium.Buffer object to receive the output data. If this argument is not provided, then the dataIn buffer will be used.
* If the resizeBuffer property is set to true, then the dataOut buffer will be resized to the size of the decrypted data
* If the resizeBuffer property is set to false, then ensure that the dataOut buffer is large enough to receive the decrypted data.
Yes
dataOutLengthNumberThe 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.Yes

Returns: Number — 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](Modules.Crypto.STATUS_ERROR) * [STATUS_PARAMERROR](Modules.Crypto.STATUS_PARAMERROR) * [STATUS_BUFFERTOOSMALL](Modules.Crypto.STATUS_BUFFERTOOSMALL) * [STATUS_MEMORYFAILURE](Modules.Crypto.STATUS_MEMORYFAILURE) * [STATUS_ALIGNMENTERROR](Modules.Crypto.STATUS_ALIGNMENTERROR) * [STATUS_DECODEERROR](Modules.Crypto.STATUS_DECODEERROR) * [STATUS_UNIMPLEMENTED](Modules.Crypto.STATUS_UNIMPLEMENTED)

Titanium SDK Documentation