File encryption with MCRYPT and MS Office 2007
Posted: Wed Jun 17, 2009 3:00 pm
I've been using the following code for quite some time with no issue at all, until I had to use it for encrypting MS Office 2007 files (docx, xlsx, pptx...). The code creates an encrypted file, but once decrypted it can not be read by the Office application. Same issue with 128 or 256 bits.
Do you know how can that be? is there something peculiar in how to ...x files are built?
Thank so much for you help.
Jean-Louis
function file_encrypt($content, $key)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_128, $key, $content, MCRYPT_MODE_ECB, $iv);
return $content;
}
function file_decrypt($content, $key)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decryptedpass = mcrypt_decrypt (MCRYPT_RIJNDAEL_128, $key, $content, MCRYPT_MODE_ECB, $iv);
return $content;
}
Do you know how can that be? is there something peculiar in how to ...x files are built?
Thank so much for you help.
Jean-Louis
function file_encrypt($content, $key)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$cryptedpass = mcrypt_encrypt (MCRYPT_RIJNDAEL_128, $key, $content, MCRYPT_MODE_ECB, $iv);
return $content;
}
function file_decrypt($content, $key)
{
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decryptedpass = mcrypt_decrypt (MCRYPT_RIJNDAEL_128, $key, $content, MCRYPT_MODE_ECB, $iv);
return $content;
}