Skip to content

Instantly share code, notes, and snippets.

@bubba-h57
Created July 22, 2012 04:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bubba-h57/3158485 to your computer and use it in GitHub Desktop.
Save bubba-h57/3158485 to your computer and use it in GitHub Desktop.
PHP Compatible PERL mcrypt function
$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);
}
<?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