• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 706
  • Last Modified:

How to do encryption in PHP equal to Perl's bz_crypt() function?

What is the equivalent PHP code for the following Perl code?
(Note there is no salt arg, there is just one argument for a plaintext $password.)
I need to be able to create the identical encrypted password as in Perl.
my $cryptpassword = bz_crypt($password);

Open in new window

0
DigitalDave1
Asked:
DigitalDave1
1 Solution
 
eft0Commented:
PHP now contains its own implementation for the MD5 crypt, Standard DES, Extended DES and the Blowfish algorithms and will use that if the system lacks of support for one or more of the algorithms.

You can get more info at: http://php.net/crypt
$cryptpassword = crypt($password);

Open in new window

0
 
DigitalDave1Author Commented:
Thanks for the tip. The PHP function crypt() has some similarities to crypt() in Perl.

I was able to find some Perl documentation about bz_crypt() and with your tip, I put together something that works...
private function bz_crypt( $in_plainText ) {
		
   // verify we can do the two-character salt with DES encryption:
   if (1 != CRYPT_STD_DES) {
      return false;
   }
 
   static $strCharset = 
		     '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./';
 
   $len  = strlen ($strCharset);
   $idx1 = rand (0, $len - 1);
   $idx2 = rand (0, $len - 1);
   $salt = substr ($strCharset, $idx1, 1) . 
           substr ($strCharset, $idx2, 1);
 
   return crypt ($in_plainText, $salt);    
		       
} /* end bz_crypt() private function definition */

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now