Skip to content

Instantly share code, notes, and snippets.

/crypto.pl Secret

Created January 25, 2018 06:21
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 anonymous/a229b77c8ab25026633f1ab819c29a78 to your computer and use it in GitHub Desktop.
Save anonymous/a229b77c8ab25026633f1ab819c29a78 to your computer and use it in GitHub Desktop.
#!/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