You are here

function aes_get_key in AES encryption 5

Same name and namespace in other branches
  1. 6 aes.module \aes_get_key()
  2. 7 aes.module \aes_get_key()
3 calls to aes_get_key()
aes_config_submit in ./aes.module
aes_decrypt in ./aes.module
Decrypts a string of encrypted data.
aes_encrypt in ./aes.module
Encrypts a string.

File

./aes.module, line 328

Code

function aes_get_key() {
  $storage_method = variable_get("aes_key_storage_method", "database");
  if ($storage_method == "Database") {
    $key = variable_get("aes_key", false);
    if ($key === false) {
      $key = aes_make_key();
      aes_store_key($key);
      if (user_access('administer aes')) {
        drupal_set_message(t("AES module made a new key since one couldn't be found by using the database storage method."));
      }
      watchdog("aes", "AES module made a new key since one couldn't be found by using the database storage method.");
    }
  }
  if ($storage_method == "File") {
    $key = file_get_contents(variable_get("aes_key_path", ""));
    if ($key === false) {
      $key = aes_make_key();
      aes_store_key($key);
      if (user_access('administer aes')) {
        drupal_set_message(t("AES module made a new key since one couldn't be found by using the file storage method."));
      }
      watchdog("aes", "AES module made a new key since one couldn't be found by using the file storage method.");
    }
  }
  return $key;
}