3

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!

0

1 Answer 1

5

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.