To provide an encryption method to the Encrypt API module, you need to do a couple things:
function encrypt_ctools_plugin_directory($module, $plugin) { if ($module == 'encrypt') { return 'plugins/' . $plugin; } }So, with this implementation, ctools will look for encryption method plugins in plugins/encryption_methods and key provider plugins in plugins/key_providers. You can load plugins however you'd like, but this is sort of a ctools standard.
$plugin = encrypt_mcrypt_aes_cbc_encrypt_encryption_methods(); /** * Implements MODULE_FILENAME_encrypt_encryption_methods(). */ function encrypt_mcrypt_aes_cbc_encrypt_encryption_methods() { return array( 'title' => t('Mcrypt AES (CBC Mode)'), 'description' => t('Uses PHP\'s Mcrypt extension and AES in CBC mode. The key MUST be 16, 24, or 32 bytes.'), 'encrypt callback' => '_encrypt_encryption_methods_mcrypt_aes_cbc', 'dependency callback' => '_encrypt_mcrypt_extension_is_present', ); }Available options for the $plugin array include:
/** * Callback to see if the Mcrypt library is present. */ function _encrypt_mcrypt_extension_is_present() { $errors = array(); if (!function_exists('mcrypt_encrypt')) { $errors[] = t('Mcrypt library not installed.'); } return $errors; }
/** * @param $op * The operation currently being performed. 'encrypt' for encrypting, 'decrypt' for decrypting * * @param $text * The string to be encrypted or decrypted. * * @param $key * The encryption key to use for encrypting. Provided by the active key provider. * * @param $options * An array of additional parameters. * * @return * The processed (either encrypted or decrypted, depending on $op) string. */ function your_encryption_callback($op = 'encrypt', $text = '', $key, $options = array()) { // Do stuff. }