Is it possible to decrypt files encrypted with php mcrypt_encode with third party utilities?
I am inexperienced with symmetric encryption. I am encrypting a pdf file in php using the following code:
$source_filepath = RB::get('docroot') . RB::get('baseUrl') . '/submissions/' . $this->_filename;
$encrypted_filepath = $source_filepath . '.nc';
$pdf_data = file_get_contents($source_filepath);
$encrypted_data = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, '1234567812345678', $pdf_data, MCRYPT_MODE_ECB);
file_put_contents($encrypted_filepath, $encrypted_data);
Then I need to decrypt it outside of php, potentially using a desktop application/utility on another computer. I have attempted to decrypt the file with the aescrypt utility (http://www.aescrypt.com/) which tells me:
"Error: Bad file header (not aescrypt file or is corrupted? [c, fffffff0, fffffffe])"
as well as the mcrypt command which tells me: File thefile.pdf.nc was NOT decrypted successfully.
I have yet to be able to decrypt anything encrypted with encrypt outside of php. I have tried using blowfish and decrypting it with bcrypt (http://bcrypt.sourceforge.net/) as well with similar results. I suspect my ignorance of how encryption works is to blame but any help or education would be appreciat开发者_如何学JAVAed. Thanks.
I am encrypting a pdf file in php using the following code:
The reason your getting an error from aescrypt is because the file you are writing has nothing to with the AEScrypt file format. Fortunately the developers of AESCrypt have provided very detailled instructions on their file format.
If after implementing that you're still having problems, then you could try the AESCrypt mailing list and failing that you could even contact the developers and offer to sponsor development of a cmpatible encryptor/decryptor in PHP.
I'm don't know PHP or mcrypt but just based on the calling line I suspect you could decrypt the file with the openssl command-line utility. The following example should close to what you need:
openssl aes-128-ecb -d -K 303132333435363738303132333435363738 -iv 00000000000000000000000000000000 -P -nopad -nosalt -in cipherfile -out plainfile
NOTE: You'll have to strip off any padding yourself. mcrypt_encrypt apparently tacks on '\0' characters to pad the data to a multiple of the blocksize.
精彩评论