2

I have a string to encyrpt:

$encryptThis = "Super Secret Text";
echo openssl_encrypt($encryptThis, 'aes-128-cbc', '1234', FALSE, 'F68A9A229A516752');

I then wget get the that php file and end up with what looks like a base64 string of characters.

When I try to decode it on the command line I get "error reading input file". The command I am using to try and decrypt is:

openssl aes-128-cbc -a -iv F68A9A229A516752 -d -in encrypted.txt -out decypted.txt

encrypted.txt is the file name that I saved the file I wget'ed to. What am I missing?

2
  • Only thing I can see is 'decypted.txt' instead of 'decrypted.txt'.. if you do a cat or less from the command line, does the file open correctly? Commented Dec 22, 2010 at 18:11
  • Yes, the file opens fine. That was a typo so I don't think that is the issue. Commented Dec 23, 2010 at 21:21

3 Answers 3

2

The file encrypted.txt is not in the correct format for the command line OpenSSL. It is expecting your data to begin with the string Salted__, followed by a salt. Your file does not have this format, and therefore OpenSSL prints "error reading input file" (from apps/enc.c in the OpenSSL source code).

Note that in a Base64 file, the header is not the plain text Salted__, but is rather U2FsdGVkX1.

So do cat encrypted.txt from the command line and see what it contains.

(I do not know whether PHP's openssl_encrypt is supposed to produce output in this format, but I would assume so if it's just a thin wrapper around OpenSSL's command-line utility.)

Sign up to request clarification or add additional context in comments.

1 Comment

I tried using -nosalt as well on the command line still no luck.
2

I finally ended up just making a shell script that is called using php exec(). I never could get PHP built in functions to decode on the command line.

Comments

0

I guess in your encrypted and base64 encoded file, you have long lines, possibly even everything on a single line. Insert a linefeed after every 64 characters and then openssl should be able to decode it.

Openssl (at least the versions I tested) does not properly base64 decode files with lines longer than 64 characters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.