# Modules.Crypto

Add-on Crypto module

Availability
4.0.0
4.0.0

# Overview

This feature requires a Pro or Enterprise subscription!

This module provides access to various encryption and decryption algorithms, and string encodings.

# Getting Started

View the Using Titanium Modules (opens new window) document for instructions on getting started with using this module in your application.

# Accessing the crypto Module

To access this module from JavaScript, you would do the following:

var crypto = require("ti.crypto");

The crypto variable is a reference to the Module object.

# Methods

# decodeData

Availability
4.0.0
4.0.0
decodeData(dictionary) String

Decodes a source buffer into a string using the specified data type. This is a codec method used for converting data from a source buffer into a displayable string.

Parameters

Name Type Description
dictionary DecodeDataDict

a dictionary with keys

Returns

Returns the decoded string

Type
String

# encodeData

Availability
4.0.0
4.0.0
encodeData(dictionary) Number

Encodes the source into the destination buffer using the specified data type. This is a codec method used for converting data to a destination buffer.

Parameters

Name Type Description
dictionary EncodeDataDict

a dictionary with keys

Returns

Returns the position after the encoded data inside the destination.

Type
Number

# Constants

# ALGORITHM_3DES

Availability
4.0.0
4.0.0
ALGORITHM_3DES :Number

Set on the algorithm property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used.

See Triple_DES for more details.


# ALGORITHM_AES128

Availability
4.0.0
4.0.0
ALGORITHM_AES128 :Number

Set on the algorithm property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used.

See Advanced_Encryption_Standard for more details.


# ALGORITHM_CAST

Availability
4.0.0
4.0.0
ALGORITHM_CAST :Number

Set on the algorithm property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used.

See CAST-128 for more details.


# ALGORITHM_DES

Availability
4.0.0
4.0.0
ALGORITHM_DES :Number

Set on the algorithm property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used.

See Data_Encryption_Standard for more details.


# ALGORITHM_RC2

Availability
4.0.0
4.0.0
ALGORITHM_RC2 :Number

Set on the algorithm property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used. See RC2 for more details.


# ALGORITHM_RC4

Availability
4.0.0
4.0.0
ALGORITHM_RC4 :Number

Set on the algorithm property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used. See RC4 for more details.

Note that while defined on Android, this algorithm is unimplemented.


# BLOCKSIZE_3DES

Availability
4.0.0
4.0.0
BLOCKSIZE_3DES :Number

Number of bytes for blocks of the related algorithm.


# BLOCKSIZE_AES128

Availability
4.0.0
4.0.0
BLOCKSIZE_AES128 :Number

Number of bytes for blocks of the related algorithm.


# BLOCKSIZE_CAST

Availability
4.0.0
4.0.0
BLOCKSIZE_CAST :Number

Number of bytes for blocks of the related algorithm.


# BLOCKSIZE_DES

Availability
4.0.0
4.0.0
BLOCKSIZE_DES :Number

Number of bytes for blocks of the related algorithm.


# BLOCKSIZE_RC2

Availability
4.0.0
4.0.0
BLOCKSIZE_RC2 :Number

Number of bytes for blocks of the related algorithm.


# DECRYPT

Availability
4.0.0
4.0.0
DECRYPT :Number

Set on the operation property. Used in the update and finish methods to indicate the operation should be to decrypt data.


# ENCRYPT

Availability
4.0.0
4.0.0
ENCRYPT :Number

Set on the operation property. Used in the update and finish methods to indicate the operation should be to encrypt data.


# KEYSIZE_3DES

Availability
4.0.0
4.0.0
KEYSIZE_3DES :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_AES128

Availability
4.0.0
4.0.0
KEYSIZE_AES128 :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_AES192

Availability
4.0.0
4.0.0
KEYSIZE_AES192 :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_AES256

Availability
4.0.0
4.0.0
KEYSIZE_AES256 :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_DES

Availability
4.0.0
4.0.0
KEYSIZE_DES :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_MAXCAST

Availability
4.0.0
4.0.0
KEYSIZE_MAXCAST :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_MAXRC2

Availability
4.0.0
4.0.0
KEYSIZE_MAXRC2 :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_MAXRC4

Availability
4.0.0
4.0.0
KEYSIZE_MAXRC4 :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_MINCAST

Availability
4.0.0
4.0.0
KEYSIZE_MINCAST :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_MINRC2

Availability
4.0.0
4.0.0
KEYSIZE_MINRC2 :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# KEYSIZE_MINRC4

Availability
4.0.0
4.0.0
KEYSIZE_MINRC4 :Number

Number of bytes used to hold a key of the given type. Useful for creating instances of Titanium.Buffer to generate a key for the key property used in the encrypt, decrypt, update and finish methods.


# OPTION_ECBMODE

Availability
4.0.0
4.0.0
OPTION_ECBMODE :Number

Set on the options property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used. See Wikipedia for more details.


# OPTION_PKCS7PADDING

Availability
4.0.0
4.0.0
OPTION_PKCS7PADDING :Number

Set on the options property. Used in the encrypt, decrypt, update and finish methods to indicate the algorithm used. See Wikipedia for more details.


# STATUS_ALIGNMENTERROR

Availability
4.0.0
4.0.0
STATUS_ALIGNMENTERROR :Number

Used in the encodeData and Modules.Crypto.Cryptor methods to report an error. This means that the data you are passing is not correctly padded (specifically that the entire data length including padding is not a multiple of the block size). The most likely cause is that you are truncating your encrypted data somewhere, possibly outside of this routine.

Only reported by iOS (though the constant is still defined on Android).


# STATUS_BUFFERTOOSMALL

Availability
4.0.0
4.0.0
STATUS_BUFFERTOOSMALL :Number

Used in the encodeData and Modules.Crypto.Cryptor methods to report an error when the buffer is not long enough to contain the result.


# STATUS_DECODEERROR

Availability
4.0.0
4.0.0
STATUS_DECODEERROR :Number

Used in the encodeData and Modules.Crypto.Cryptor methods to report an error. Input data did not decode or decrypt properly.

Only reported by iOS (though the constant is still defined on Android).


# STATUS_ERROR

Availability
4.0.0
4.0.0
STATUS_ERROR :Number

Used in the Modules.Crypto.Cryptor methods to report a generic error for an operation.


# STATUS_MEMORYFAILURE

Availability
4.0.0
4.0.0
STATUS_MEMORYFAILURE :Number

Used in the encodeData and Modules.Crypto.Cryptor methods to report an error with allocating memory.

Only reported by iOS (though the constant is still defined on Android).


# STATUS_PARAMERROR

Availability
4.0.0
4.0.0
STATUS_PARAMERROR :Number

Used in the encodeData and Modules.Crypto.Cryptor methods to report an error with the supplied parameters or properties.


# STATUS_SUCCESS

Availability
4.0.0
4.0.0
STATUS_SUCCESS :Number

Used in the reset and release methods to report success for the operation.


# STATUS_UNIMPLEMENTED

Availability
4.0.0
4.0.0
STATUS_UNIMPLEMENTED :Number

Used in the getOutputLength and various Modules.Crypto.Cryptor methods to report an error. Typically used to indicate the given algorithm/mode is not implemented in this OS version.

Android will report this status only on getOutputLength. Otherwise this status is only reported by iOS for the methods performing operations.


# TYPE_BASE64STRING

Availability
4.0.0
4.0.0
TYPE_BASE64STRING :Number

Used in the encodeData and decodeData methods to specify expected string format. A Base64 encoded string.


# TYPE_BLOB

Availability
4.0.0
4.0.0
TYPE_BLOB :Number

Used in the encodeData method to specify expected input is a Ti.Blob instance.


# TYPE_HEXSTRING

Availability
4.0.0
4.0.0
TYPE_HEXSTRING :Number

Used in the encodeData and decodeData methods to specify expected string format. A hexadecimal formatted string. Each byte is represented by 2 hexadecimal numbers.