Question

I'm looking at the Crypt::CBC lib and I misunderstand something... below an example :

#!/usr/bin/env perl
use warnings;
use strict;
use Crypt::CBC;

my $cipher = Crypt::CBC->new(
    -key    => pack("H*","0011223344556677"),
    -iv     => pack("H*","AABBCCDDEEFF0011"),
    -header => "none",
    -padding=> "null",
    -cipher => "Crypt::DES");
my $plaintext = $cipher->decrypt(pack("H*","0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"));
print unpack("H*",$plaintext)."\n";

This script print the string :

a732b731fdcb5dbe0caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f90400caa3e8b9a9f9040

It should be :

D7ED316D5F2C1F1D7C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E37C75B8D73878D2E3

I use CrypTool 2.0 software and http://des.online-domain-tools.com/tool-form-submit/ to get this result.

Any ideas ?


[=> Problem Solved <=]

I have fixed the issue with -literal_key => 1, parameter.

#!/usr/bin/env perl
use warnings;
use strict;
use Crypt::CBC;

my $cipher = Crypt::CBC->new(
    -literal_key => 1,
    -key    => pack("H*","0011223344556677"),
    -iv     => pack("H*","AABBCCDDEEFF0011"),
    -header => "none",
    -padding=> "null",
    -cipher => "Crypt::DES");
my $plaintext = $cipher->decrypt(pack("H*","0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"));
print unpack("H*",$plaintext)."\n";
Was it helpful?

Solution

I have fixed the issue with -literal_key => 1, parameter.

#!/usr/bin/env perl
use warnings;
use strict;
use Crypt::CBC;

my $cipher = Crypt::CBC->new(
    -literal_key => 1,
    -key    => pack("H*","0011223344556677"),
    -iv     => pack("H*","AABBCCDDEEFF0011"),
    -header => "none",
    -padding=> "null",
    -cipher => "Crypt::DES");
my $plaintext = $cipher->decrypt(pack("H*","0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"));
print unpack("H*",$plaintext)."\n";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top