开发者

PHP encrypt/decrypt default_charset problem

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 ma开发者_开发百科kes 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜