Mcrypt Win32 vs. PHP Mcrypt extension - php

I'm looking forward encrypting a file using Win32 command-line mcrypt.exe. Then decrypt it using an apache/unix based PHP script.
So I do in win's command-line:
mcrypt -a "blowfish" -k 1234 -m cbc test.txt
(test.txt is a simple text file that contains "working fine"
This generates a 47 bytes files named test.txt.nc
So I upload the file to my apache webserver and run this script:
$s = mcrypt_cbc("blowfish","1234",file_get_contents("test.txt.nc"),MCRYPT_DECRYPT);
file_put_contents("newtext.txt",$s);
I get this warning:
Warning: mcrypt_cbc() [function.mcrypt-cbc]: Attempt to use an empty IV, which is NOT recommend
And a 48 bytes newtext.txt file, which contains binary data instead of the decrypted text file
I need some guidance!. Thank you very much

Related

PHP Open SSL Decrypt Failing Inconsistently

I'm having some weird behaviour with the openssl_decrypt method in PHP. It's failing, giving me an error: Unknown cipher algorithm, but only sometimes (about 6:10 times) i.e. If I run the command enough times, it will eventually work... My code is:
$result = openssl_decrypt(base64_decode($hash), 'AES-128-CBC', $timestamp);
running openssl list-cipher-commands lists AES-128-CBC as one of the available cipher methods. The specs don't really list anything on the subject - only specifying that unknown cipher algorithm is a possible exception from running the command.
edit:
Using the command line: i.e. running echo "soemthing" | openssl enc -aes-128-cbc on a random machine and then decrypting on the machine that fails with the above echo "..." | openssl enc -aes-128-cbc -d works consistently.

Imagick is unable to open DNG images

As you can see, the image _IGP4559.DNG exists but Imagick can't open it.
JPEG images works just fine.
readImage() returns the same error.
Here is the image: http://files.patrikelfstrom.se/_IGP4559.DNG
I run this in the terminal to rule out all other variables.
$ ll /var/www/_IGP4559.DNG
-rw-rw-rw- 1 monsun monsun 11841201 May 17 03:37 /var/www/_IGP4559.DNG
$ php -a
Interactive mode enabled
php > new Imagick('/var/www/_IGP4559.DNG');
PHP Warning: Uncaught exception 'ImagickException' with message 'unable to open image `/tmp/magick-29917oe6CM9MIkN8A.ppm': No such file or directory # error/blob.c/OpenBlob/2709' in php shell code:1
Stack trace:
#0 php shell code(1): Imagick->__construct('/var/www/_IGP45...')
#1 {main}
thrown in php shell code on line 1
ImageMagick uses other programs to read some image formats, including DNG.
What is likely happening is that the program that ImageMagick expects to be able to use to read the DNG either isn't present on your system or isn't working correctly.
The file that lists these other programs is called delegates.xml
On my system the entry for DNG decoding is:
<delegate decode="dng:decode" command=""ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i""/>
i.e. it's trying to use the program 'ufraw-batch' to do the decoding, and like you're seeing it fails, as that program isn't usable on my system.
To solve this, you either need to install ufraw, or install a similar package that can convert files from the DNG format to a standard one that ImageMagick can read directly.

How to encrypt a string with GnuPG?

How can I encrypt a given string using gpg from command line?
I have the public key stored in a file called pubkey.pub
I thought I could simply do it with something like that.
gpg --import "path/to/pubkey.pub" --encrypt "my string to encrypt"
But this won't work.
Background: I have to use the PHP exec command to encrypt given text, because I don't have the PHP module itself installed on the server.
gpg reads from stdin while encrypting, thus run
echo "my string to encrypt" | gpg --encrypt
gpg --import imports key material to GnuPG's keystore, where it remains; thus you only have to call it once (and it is a rather slow operation, as it might trigger updating your trust database).

php cli on linux not working

PHP CLI has suddently stopped working on the server. When running any php file even php -v to get php version I get following error.
Thanks
# php -v
Unknown option: v
php [-f from_encoding] [-t to_encoding] [-s string] [files...]
php -l
php -r encoding_alias
-l,--list
lists all available encodings
-r,--resolve encoding_alias
resolve encoding to its (Encode) canonical name
-f,--from from_encoding
when omitted, the current locale will be used
-t,--to to_encoding
when omitted, the current locale will be used
-s,--string string
"string" will be the input instead of STDIN or files
The following are mainly of interest to Encode hackers:
-D,--debug show debug information
-C N | -c | -p check the validity of the input
-S,--scheme scheme use the scheme for conversion
Type which php on your shell to find which php executable your shell picks from your search PATH.
Use ls -l $(which php) to see if it's a symlink to some other executable.
What you see when running php -v is actually output of the piconv command.
Most possibly, there is a symlink named php pointing to piconv somewhere in your search PATH.
Type echo $PATH to see the order of directories in which your shell searches for an executable php.
EDIT:
Changed whereis to which in the command above.

how to use php call linux GPG encrypt file with a passphase

I have a task which need to
use gpg to encrypt the upload file in php
my code is:
("echo '1234' | gpg --passphrase-fd 0 -c /path/aaa.jpg ");
it works by paste the code in linux
but not work by php any solution
You need to use gnupg_decypt() to decrypt the text.

Categories