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 = array(
'title' => t('Mcrypt AES 256'),
'description' => t('This uses PHPs mcrypt extension and AES-256.', array('!url' => 'http://en.wikipedia.org/wiki/Advanced_Encryption_Standard')),
'encrypt callback' => 'encrypt_encryption_methods_mcrypt_rij_256',
'dependency callback' => 'mcrypt_extension_is_present',
);
The plugin can just be declared in the global space; no need to wrap it in a function or anything. Available options for the $plugin array include:
/**
* Callback to see if the MCrypt library is present.
*/
function _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.
}