-
-
Save anonymous/a229b77c8ab25026633f1ab819c29a78 to your computer and use it in GitHub Desktop.
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
#!/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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment