function encryption_encrypt
Search API
7.x encryption.module | encryption_encrypt($plain_contents) |
6.x encryption.module | encryption_encrypt($plain_contents) |
2 calls to encryption_encrypt()
- 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.
- 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 305 - This is the main module file for the encryption module.
Code
function encryption_encrypt($plain_contents) {
$cipher = encryption_get_cipher_algorithm();
$key = encryption_get_key();
$plaintext = base64_encode($plain_contents); // convert to base64 so binary will work as well as text files.
$ivlen = openssl_cipher_iv_length($cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
// replace OPENSSL_RAW_DATA & $iv with 0 & bin2hex($iv) for hex cipher (eg. for transmission over internet)
$ciphertext_raw = openssl_encrypt($plaintext, $cipher, $key, OPENSSL_RAW_DATA, $iv);
// increase security with hashed cipher; (hex or base64 printable eg. for transmission over internet)
$hmac = hash_hmac("sha256", $ciphertext_raw, $key, true);
return base64_encode($iv . $hmac . $ciphertext_raw);
}