- /* Extract key and iv. */
- $ex = explode (".", $k);
- $key = $ex[0];
- $iv = base64_decode($ex[1]);
- /* Init module */
- $m = mcrypt_module_open('rijndael-256', '', 'ofb', '');
- mcrypt_generic_init($m, $key, $iv);
- /* Decrypt file. */
- $r = fopen ($fp_src, 'r');
- $w = fopen ($fp_dst, 'c');
- while (!feof ($r))
- {
- $dec = mdecrypt_generic($m, fread ($r, 1024));
- if (fwrite ($w, $dec) === false)
- return false;
- }
- fclose ($r);
- fclose ($w);
- /* Cleanup. */
- mcrypt_generic_deinit($m);
- mcrypt_module_close($m);
- return true;