2

I’m having a problem in encryption using PHP crypt

Following is my code :

echo $ret = crypt('Dave@123','2ドルy10ドル$XLLl50bLyTWfjcvCAxwGRu/px2Q.LXN0fHpD1KN2CQCMx/tpL1V62');

1) When using crypt in PHP Version 5.4.22 It results:

 2ドルy10ドル$XLLl50bLyTWfjcvCAxwGRu/px2Q.LXN0fHpD1KN2CQCMx/tpL1V62

2) When used with PHP Version 5.2.17 it results

 25ドルnFTQHtfjVg

I want the same result as 1.

hakre
200k55 gold badges454 silver badges868 bronze badges
asked Feb 13, 2014 at 14:57
4
  • 3
    Are you aware that your first result from 1) shows the second input to the crypt function? I wouldn't want to get my input as output back. Commented Feb 13, 2014 at 14:58
  • @Samuel You are aware that this is intended behaviour? Commented Feb 13, 2014 at 15:09
  • PHP 5.2 is end of live. You actually don't want that. -- -1: Only wanting sth. does not qualify as a programming question. Edit: Shame on you upvoters (:)): Even more votes than the duplicate that exists for months and has answers (!). Commented May 4, 2014 at 10:08
  • possible duplicate of to use CRYPT_BLOWFISH on php 5.2 that doesn't support it Commented May 4, 2014 at 10:09

2 Answers 2

1

The issue is the 2y blowfish prefix. It was introduced after a security issue in PHP 5.3.7 and so PHP 5.2 does not know about it, sees an invalid $salt and generates an invalid hash.

The equivalent in PHP 5.2 is 2a, but it might be affected by the mentioned security issue (I did not check).

answered Feb 13, 2014 at 15:07
Sign up to request clarification or add additional context in comments.

Comments

1

From the manual. I came to know that they introduced Update 2ドルy$ Blowfish modes on 5.3.7. So in PHP 5.2.17 you may get DES. The type of hashing is decided from the salt you provides.

answered Feb 13, 2014 at 15:08

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.