Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use warnings;
- use strict;
- use Crypt::CBC;
- use MIME::Base64 qw/encode_base64 decode_base64/;
- use IPC::System::Simple qw/capture/;
- use Test::More;
- use feature 'say';
- my $key = 'blah';
- my $message = "I wish I were a metre ruler, then I would be a lot cooler";
- my $c = Crypt::CBC->new(
- -key => $key,
- -cipher => 'Blowfish',
- -keysize => 128/8,
- );
- subtest 'encrypt in perl, decrypt in openssl' => sub {
- my $enc = encode_base64 $c->encrypt($message);
- my $dec = capture "echo '$enc' | openssl enc -bf -d -k blah -a ";
- is $message, $dec, "Message and openssl decrypted match";
- };
- subtest 'encrypt in openssl, decrypt in perl' => sub {
- my $two = capture "echo '$message' | openssl enc -bf -k blah -a";
- my $dec_two = $c->decrypt(decode_base64 $two);
- chomp $dec_two; # remove trailing newline from system call
- is $message, $dec_two, "Message round trips the other way";
- };
- done_testing;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement