# Modules.Crypto
Add-on Crypto module
# 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
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
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
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
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
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
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
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
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.
# DECRYPT
Set on the operation property. Used in the update and finish methods to indicate the operation should be to decrypt data.
# ENCRYPT
Set on the operation property. Used in the update and finish methods to indicate the operation should be to encrypt data.
# KEYSIZE_3DES
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Used in the Modules.Crypto.Cryptor methods to report a generic error for an operation.
# STATUS_MEMORYFAILURE
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
Used in the encodeData and Modules.Crypto.Cryptor methods to report an error with the supplied parameters or properties.
# STATUS_SUCCESS
Used in the reset and release methods to report success for the operation.
# STATUS_UNIMPLEMENTED
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
Used in the encodeData and decodeData methods to specify expected string format. A Base64 encoded string.
# TYPE_BLOB
Used in the encodeData method to specify expected input is a Ti.Blob instance.
# TYPE_HEXSTRING
Used in the encodeData and decodeData methods to specify expected string format. A hexadecimal formatted string. Each byte is represented by 2 hexadecimal numbers.