mergAES

mergAES provides easy to use AES 128 and 256 encryption in CBC or ECB mode functions to LiveCode on iOS.
mergAES includes RNCryptor by Rob Napier.
Because as the author states there are significant security isues in the OpenSSL format the
external provides two sets of functions. The OpenSSL functions use the Salted__ style encrypted data header as OpenSSL generates and is therefore compatible with the encrypt/decrypt with password command available on LiveCode desktop platforms. The external functions on iOS 5.0 and up.
On earlier versions of iOS the functions will throw an error.

Copyright (c) 2012 Rob Napier
 This code is licensed under the MIT License:
 Permission is hereby granted, free of charge, to any person obtaining a 
 copy of this software and associated documentation files (the "Software"),
 to deal in the Software without restriction, including without limitation
 the rights to use, copy, modify, merge, publish, distribute, sublicense,
 and/or sell copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following conditions:
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 DEALINGS IN THE SOFTWARE.

Installation

To install this external open the Standalone Settings for your app and go to the Copy Files pane. For LiveCode 5.5.2+ choose the mergAES.lcext from the distribution archive. For earlier versions of LiveCode select the appropriate folder inside the Pre-LiveCode-5.5.2 folder for the version of the iOS SDK you have installed. Xcode 4.2 = iOS 5.0, Xcode 4.3-4 = iOS 5.1. Xcode 4.5 is not supported by versions of LiveCode prior to 5.5.3. Any feature marked with a minimum iOS version must be comipled against that SDK or higher even if the app is run on a higher version of iOS. If there is a resources folder then these files and folders must be selected individually so that they end up at the root of the app directory. Any files or folders inside the demo folder are required for the demo to run correctly.

Documentation

function mergAESEncrypt pData,pPassword

Encrypt the data.

Parameters:

  • pData - the data to be encrypted
  • pPassword - the password to use

Returns encrypted data in the format specified here

function mergAESDecrypt pData,pPassword

Decrypt data.

Parameters:

  • pData - data to be decrypted in the format specified here
  • pPassword - the password to use

Returns unencrypted data

function mergAESOpenSSLEncrypt pData,pPassword,[pMode],[pKeySize],[pPadding]

Encrypt data and return with an OpenSSL style Salted__ header.

Parameters:

  • pData - the data to be encrypted
  • pPassword - the password to use
  • pMode - (optional with "cbc" default) the cipher mode. One of:
    • cbc
    • ecb
  • pKeySize - (optional with "256" default) the key size. One of:
    • 256
    • 128
  • pPadding - (optional with "PKCS7" default) the padding option to use. One of:
    • PKCS7 - For openSSL compatibilty
    • none - Not compatible with openSSL and requires the string to be encrypted to be a multiple of the key size. That means the for 128 bit the number of characters needs to be divisible by 16.

Returns encrypted data in OpenSSL comapatible format (aes-cbc,256)

function mergAESOpenSSLDecrypt pData,pPassword,[pMode],[pKeySize],[pPadding]

Decrypt data with an OpenSSL style Salted__ header.

Parameters:

  • pData - data to be decrypted in OpenSSL comapatible format (aes-cbc,256)
  • pPassword - the password to use
  • pMode - (optional with "cbc" default) the cipher mode. One of:
    • cbc
    • ecb
  • pKeySize - (optional with "256" default) the key size. One of:
    • 256
    • 128
  • pPadding - (optional with "PKCS7" default) the padding option to use. One of:
    • PKCS7 - For openSSL compatibilty
    • none - Not compatible with openSSL and requires the string to be encrypted to be a multiple of the key size. That means the for 128 bit the number of characters needs to be divisible by 16.

Returns unencrypted data

function mergAESEncryptWithKey pData,pKey,pIV,[pMode],[pKeySize],[pPadding]

Encrypt data using a known key and if required IV.

Parameters:

  • pData - the data to be encrypted
  • pKey - the key to use
  • pIV - the IV to use
  • pMode - (optional with "cbc" default) the cipher mode. One of:
    • cbc
    • ecb
  • pKeySize - (optional with "256" default) the key size. One of:
    • 256
    • 128
  • pPadding - (optional with "PKCS7" default) the padding option to use. One of:
    • PKCS7 - For openSSL compatibilty
    • none - Not compatible with openSSL and requires the string to be encrypted to be a multiple of the key size. That means the for 128 bit the number of characters needs to be divisible by 16.

Returns encrypted data

function mergAESDecryptWithKey pData,pKey,pIV,[pMode],[pKeySize],[pPadding]

Decrypt data using a known key and if required IV.

Parameters:

  • pData - data to be decrypted
  • pKey - the key to use
  • pIV - the IV to use
  • pMode - (optional with "cbc" default) the cipher mode. One of:
    • cbc
    • ecb
  • pKeySize - (optional with "256" default) the key size. One of:
    • 256
    • 128
  • pPadding - (optional with "PKCS7" default) the padding option to use. One of:
    • PKCS7 - For openSSL compatibilty
    • none - Not compatible with openSSL and requires the string to be encrypted to be a multiple of the key size. That means the for 128 bit the number of characters needs to be divisible by 16.

Returns unencrypted data