Created
July 22, 2012 04:52
-
-
Save bubba-h57/3158485 to your computer and use it in GitHub Desktop.
PHP Compatible PERL mcrypt function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$encryptedString = '7DjnpOXG+FrUaOuc8x6vyrkk3atSiAf425ly5KpG7lOYgwouw2UATw=='; | |
$iv = '12345678'; | |
$passphrase = '8chrsLng'; | |
$string = &decryptPhpEncrypted $encryptedString, $passphrase, $iv; | |
# Expect: Some Secret thing I want to encrypt | |
sub decryptPhpEncrypted() { | |
my ($encryptedString, $passphrase, $iv) = @_; | |
my $keysize = length($passphrase); | |
use Crypt::CBC; | |
$cipher = Crypt::CBC->new( {'key' => $encryptedString, | |
'cipher'=> 'Blowfish', | |
'iv' => $iv, | |
'keysize' => $keysize, | |
'regenerate_key' => 0, | |
'padding' => 'null', | |
'prepend_iv' => 0}); | |
return $cipher->decrypt($encryptedString); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$string = 'Some Secret thing I want to encrypt'; | |
$iv = '12345678'; | |
$passphrase = '8chrsLng'; | |
$encryptedString = encryptString($string, $passphrase, $iv); | |
// Expect: 7DjnpOXG+FrUaOuc8x6vyrkk3atSiAf425ly5KpG7lOYgwouw2UATw== | |
function encryptString($unencryptedText, $passphrase, $iv) { | |
$enc = mcrypt_encrypt(MCRYPT_BLOWFISH, $passphrase, $unencryptedText, MCRYPT_MODE_CBC, $iv); | |
return base64_encode($enc); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment