Advertisement
Guest User

Perl is unreadable/s

a guest
May 25th, 2018
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.95 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use warnings;
  3. use strict;
  4. use Crypt::CBC;
  5. use MIME::Base64 qw/encode_base64 decode_base64/;
  6. use IPC::System::Simple qw/capture/;
  7. use Test::More;
  8.  
  9. use feature 'say';
  10.  
  11. my $key = 'blah';
  12. my $message = "I wish I were a metre ruler, then I would be a lot cooler";
  13.  
  14. my $c = Crypt::CBC->new(
  15.     -key => $key,
  16.     -cipher => 'Blowfish',
  17.     -keysize => 128/8,
  18. );
  19.  
  20. subtest 'encrypt in perl, decrypt in openssl' => sub {
  21.     my $enc = encode_base64 $c->encrypt($message);
  22.     my $dec = capture "echo '$enc' | openssl enc -bf -d -k blah  -a ";
  23.     is $message, $dec, "Message and openssl decrypted match";
  24. };
  25.  
  26. subtest 'encrypt in openssl, decrypt in perl' => sub {
  27.     my $two = capture "echo '$message' | openssl enc -bf -k blah -a";
  28.  
  29.     my $dec_two = $c->decrypt(decode_base64 $two);
  30.     chomp $dec_two; # remove trailing newline from system call
  31.     is $message, $dec_two, "Message round trips the other way";
  32. };
  33.  
  34. done_testing;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement