You are here

function _encrypt_encryption_methods_phpseclib in Encrypt 7.3

Same name and namespace in other branches
  1. 7.2 plugins/encryption_methods/phpseclib.inc \_encrypt_encryption_methods_phpseclib()

Callback for Encrypt implementation: phpseclib.

This method uses the PHP Secure Communications Library and AES-256. Base64 encoding is used by default, unless disabled by setting 'base64' to FALSE in $options.

1 string reference to '_encrypt_encryption_methods_phpseclib'
encrypt_phpseclib_encrypt_encryption_methods in plugins/encryption_methods/phpseclib.inc
Implements MODULE_FILENAME_encrypt_encryption_methods().

File

plugins/encryption_methods/phpseclib.inc, line 29

Code

function _encrypt_encryption_methods_phpseclib($op, $text, $key, $options = array()) {
  $processed_text = '';
  $disable_base64 = array_key_exists('base64', $options) && $options['base64'] == FALSE;

  // If we're decrypting and base64 encoding is not disabled.
  if ($op == 'decrypt' && !$disable_base64) {
    $text = base64_decode($text);
  }
  if ($path = libraries_get_path('phpseclib')) {

    // Include the AES file and instantiate.
    require_once $path . '/Crypt/AES.php';
    $aes = new Crypt_AES();
    $aes
      ->setKey($key);
    $processed_text = $aes
      ->{$op}($text);
  }

  // If we're encrypting and base64 encoding is not disabled.
  if ($op == 'encrypt' && !$disable_base64) {
    $processed_text = base64_encode($processed_text);
  }
  return trim($processed_text);
}