I'm quite new with PHP, i'm trying to make aes encryption on mp3 files, using IV from java and key from keystore, i recived key and iv in string form using BASE64 // System.out.println(DatatypeConverter.printBase64Binary(IV)); IV is here byte array. Here is part of my php code which shoudl encrypt file
$handle = fopen($file, "r");
$contents = fread($handle, filesize($file));
fclose($handle);
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CTR, '');
$key = 'K/JED6M3WiSwke2ZZHvDInbRkUCI5lLk292ti9Bazmw=';
$iv = 'AAAAAQQFBgcAAAAAAAAAAQ==';
// Encrypt
if (mcrypt_generic_init($cipher, $key, $iv) != -1)
{
$encrypted = mcrypt_generic($cipher, $contents);
mcrypt_generic_deinit($cipher);
$info = pathinfo($file);
$nowa = $info['dirname']
. DIRECTORY_SEPARATOR
. $info['filename']
. '.'
. "mp3enc";
echo $nowa;
file_put_contents($nowa,$encrypted);
}
But encryption does not works, new file is not being created. anyway i dont see what im doing wrong, so if anyone has any suggestion i woudl be greatful for them
$nowa, does it look like it should? What is the return value from thefile_put_contents()call? Does that wholeifstatement get called?