function encrypt_encrypt_mcrypt_rij_256 in Encrypt 7
Same name and namespace in other branches
- 6 includes/encrypt.encrypt.inc \encrypt_encrypt_mcrypt_rij_256()
Callback for Encrypt implementation: Mcrypt
This method uses a PHPs mcrypt extension and AES-256
1 string reference to 'encrypt_encrypt_mcrypt_rij_256'
- encrypt_encrypt_method_info in includes/
encrypt.encrypt.inc - Implementation of hook_encrypt_method_info().
File
- includes/
encrypt.encrypt.inc, line 93 - This file holds the hook implementation for the encrypt modules
Code
function encrypt_encrypt_mcrypt_rij_256($op = 'encrypt', $text = '', $options = array()) {
$processed_text = '';
// Check for key
if (!empty($options['key'])) {
$key = $options['key'];
}
else {
$key = variable_get('drupal_private_key', 'no_key');
}
// Key cannot be too long for this encryption
$key = drupal_substr($key, 0, 32);
// Define iv cipher
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$use_base64 = array_key_exists('base64', $options) && $options['base64'] !== FALSE;
// Check op
if ($op == 'decrypt') {
// Decrypt
// Check if we are using base64 encoding
if ($use_base64) {
$text = base64_decode($text);
}
// Decrypt text
$processed_text = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
}
else {
// Encrypt
$processed_text = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
// Check if we are using base64 encoding
if ($use_base64) {
$processed_text = base64_encode($processed_text);
}
}
return trim($processed_text);
}