function encryption_get_key
Search API
7.x encryption.module | encryption_get_key() |
6.x encryption.module | encryption_get_key() |
Returns back a suitable key, either from our string or file location.
We are going to convert either one into a SHA1 string
4 calls to encryption_get_key()
- content_add_new_uploaded_file in modules/
content/ content.module - bool_replace_existing means should we replace an existing file (based on filename) with this new one? Instead of creating an INSERT, that is.
- encryption_decrypt in modules/
encryption/ encryption.module - This will decrypt an encrypted string.
- encryption_encrypt in modules/
encryption/ encryption.module - student_files_handle_upload in modules/
student_files/ student_files.module - Handles the upload of a file which we assume is located at $_FILES["student_file_upload_file"], or the provided $file array.
File
- modules/
encryption/ encryption.module, line 216 - This is the main module file for the encryption module.
Code
function encryption_get_key() {
$encryption_key_path = trim(variable_get("encryption_key_path", ""));
if ($encryption_key_path != "") {
$contents = trim(file_get_contents($encryption_key_path));
if ($contents) {
$encryption_key_string = openssl_digest($contents, "sha256", TRUE);
}
}
else {
if (!isset($GLOBALS ['encryption_key_string'])) {
fp_add_message("No encryption key has been set. The encrypt module will cause unforseen problems.", "error");
return FALSE;
}
$encryption_key_string = openssl_digest($GLOBALS ['encryption_key_string'], "sha256", TRUE);
}
if (!$encryption_key_string) {
fp_add_message("No encryption key has been set. The encrypt module will cause unforseen problems. Do not proceed until this issue is corrected.", "error");
return FALSE;
}
/*
//I don't think this is true anymore...
// The key must be a smaller size than the hash algorithm we have chosen. This is because our AES encryption is 128 bit, meaning
// they key must be 256 bits or less (32 characters). We will take a substring for 32 chars in this case.
//$encryption_key_string = substr($encryption_key_string, 0, 32);
*/
return $encryption_key_string;
}