You are here

function webform2pdf_hash in Webform2PDF 7.4

Encrypt/decrypt user input.

Parameters

string $action: "encrypt" or "decrypt" actions.

string $string: String for encryption/decryption.

Return value

bool|string FALSE if one of argument is not correct or value.

2 calls to webform2pdf_hash()
webform2pdf_url_decode in includes/webform2pdf.download.inc
webform2pdf_url_encode in ./webform2pdf.module

File

./webform2pdf.module, line 264

Code

function webform2pdf_hash($action, $string) {
  $method = 'AES-256-CBC';
  $key = hash('sha256', drupal_get_hash_salt());

  // Encrypt method (AES-256-CBC) expects 16 bytes, else you'll get a warning.
  $iv = substr(hash('sha256', variable_get('webform2pdf_key', '')), 0, 16);
  switch ($action) {
    case 'encrypt':
      return base64_encode(openssl_encrypt($string, $method, $key, 0, $iv));
    case 'decrypt':
      return openssl_decrypt(base64_decode($string), $method, $key, 0, $iv);
  }
  return FALSE;
}