Link to home
Start Free TrialLog in
Avatar of mattaustin
mattaustin

asked on

Crypt CBC with DES3 (from python)

I am trying to convert the folowing python code to perl..
------------------------------------------------------
from Crypto.Cipher import DES3

CALC_3DES = 0x6603
iv = 'testtest'
key = 'testtesttesttest'
nonce = 'testtest'
obj = DES3.new(key, DES3.MODE_CBC, iv)
ciph = obj.encrypt(nonce)
print ciph
------------------------------------------------------
But i get a diffrent output with this:
------------------------------------------------------
use Crypt::CBC;
$iv = 'testtest';
$key = 'testtesttesttest';

$cipher = Crypt::CBC->new(
              -cipher      => DES_EDE3,
                        -key         => $key,
                        -iv          => $iv,
                        -header      => 'none');

$ciphertext = $cipher->encrypt("testtest");
print $ciphertext;
------------------------------------------------------
any ideas?
Avatar of mattaustin
mattaustin

ASKER

I think it has something do to with CALC_3DES = 0x6603, but i dont know what that is or how to use it...?
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you, But how exactly did you figure that out?  Did i miss something in a doc or something?
The python documentation blows to put it mildly.   I just did a bit of experimentation and set some flags based on the Crypt::CBC documentation (http://search.cpan.org/~lds/Crypt-CBC-2.22/CBC.pm) that made sense to set based on the results I was seeing from the python encrypt.  If you have the choice, I'd change your python key to be 24 bytes.   I don't know if it's common practice to reuse the first 8 of the key for the final encrypt (just guessed that it was-- makes sense that it is) but to be on the safe side I'd go with the full key.