I'm writing some server code in PHP and I have an offline process written in Perl and they need to communicate via encrypted strings. In PHP I have been using:
$encrypted_string = openssl_encrypt($my_string, "aes-128-cbc", "my_password", true, "1234567812345678");
I'd basically like to achieve the exact same string output using Perl. Any help with how I would do this is appreciated. Thanks!
I figured it out and can now reproduce identical output encrypting a string in Perl and PHP:
Perl:
use Crypt::CBC;
use MIME::Base64;
my $cipher = Crypt::CBC->new(
{
'key' => 'length16length16',
'cipher' => 'Crypt::OpenSSL::AES',
'iv' => '1234567812345678',
'literal_key' => 1,
'header' => 'none',
keysize => 128 / 8
}
);
print encode_base64($cipher->encrypt($my_string), "");
PHP:
echo openssl_encrypt($my_string, "aes-128-cbc", "length16length16", true, "1234567812345678");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With