function drd_server_aes_encrypt in Drupal Remote Dashboard Server 6.2
Same name and namespace in other branches
- 7.2 drd_server.aes.inc \drd_server_aes_encrypt()
1 call to drd_server_aes_encrypt()
- drd_server_output in ./
drd_server.module - Prepare the output to be sent back to the DRD dashboard. This preparation json encodes the output and then encrypts the resulting string if encryption is available.
File
- ./
drd_server.aes.inc, line 3
Code
function drd_server_aes_encrypt($string, $base64encode, $key, $cipher, $iv, $implementation) {
if (empty($string)) {
return FALSE;
}
# Decode the key
$key = base64_decode($key);
if ($implementation == 'phpseclib') {
_drd_server_aes_load_phpsec();
$phpsec = new Crypt_AES();
$phpsec
->setKey($key);
if (!empty($iv)) {
$phpsec
->setIV($iv);
}
$encrypted = $phpsec
->encrypt($string);
}
else {
if ($implementation == 'mcrypt') {
$td = mcrypt_module_open($cipher, '', MCRYPT_MODE_CBC, '');
$ks = mcrypt_enc_get_key_size($td);
$key = substr(sha1($key), 0, $ks);
mcrypt_generic_init($td, $key, $iv);
$encrypted = mcrypt_generic($td, $string);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
}
else {
return FALSE;
}
}
if ($base64encode) {
return base64_encode($encrypted);
}
else {
return $encrypted;
}
}