You are here

function aes_store_key in AES encryption 7

Same name and namespace in other branches
  1. 5 aes.module \aes_store_key()
  2. 6 aes.module \aes_store_key()

Stores the key given by writing it to the storage method currently used (database or file).

Parameters

string $key: The key.

Return value

bool TRUE on success, FALSE otherwise.

2 calls to aes_store_key()
aes_config_submit in ./aes.admin.inc
Submits aes_config form.
aes_get_key in ./aes.module
Gets the current key used for the encryption system. If there's currently no key defined, this function will generate one, store it, and return it.

File

./aes.module, line 365
Main file of the AES encryption module.

Code

function aes_store_key($key) {
  $storage_method = variable_get("aes_key_storage_method", "Database");
  if ($storage_method == "Database") {
    variable_set("aes_key", $key);
    return TRUE;
  }
  if ($storage_method != "File") {
    throw new Exception('Unknown storage method in AES module: ' . $storage_method);
  }
  $fp = fopen(variable_get("aes_key_path", ""), "w");
  if ($fp === FALSE) {
    drupal_set_message(t("Couldn't write key to file " . variable_get("aes_key_path", "")), "error");
    return FALSE;
  }
  fwrite($fp, $key);
  fclose($fp);
  return TRUE;
}