1

I need to encrypt files at one computer and open it another one using PHP without external libraries. The code should work at both PHP4 and PHP5.

Encryption function makes str_split of the string and encodes each character (ord) using str_split of password. Then it makes chr and I get binary data. This binary data is encoded using base64_encode and I get ascii string.

I transfer this file to another computer who knows the password. I make base64_decode and make decrypt.

The problem appeares sometimes because the first computer has ASCII default_charset and second has UTF-8. That's why nth-char $temproraryBinaryString[$n-1] may have different values at these computers.

Can I ask PHP to treat all strings as ASCII if I cannot control php.ini at any of this computers?

2
  • Don’t reinvent the wheel but use an existing encryption algorithm. Commented May 20, 2011 at 16:24
  • possible duplicate of Best way to use PHP to encrypt and decrypt? Commented May 20, 2011 at 16:45

2 Answers 2

1

Take a look at the discussion on this post, as it talks about two-way encryption, using PHP mcrypt, which is what you should use. Two-way encryption: I need to store passwords that can be retrieved

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

1 Comment

+ oned for mcrypt, just be aware the 2 servers need the same php versions. Too lazy to look it up myself but I think the implementation or something changed between earlier version and 5.3.
0

I wrongly flagged as duplicated but it's not, what you're talking is encoding not encryption, just try:

$ascii = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $string);

This should give you a clean ASCII string to work on with str_split() and so on.

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.