Monday, April 5, 2010

OpenSSL compatible encryption

I wanted to have a Perl program that encrypted a file using perl's Crypt::CBC and be able to decrypt it using the OpenSSL enc application. It took me awhile to figure this one out.

my $cipher = Crypt::CBC->new(
-key => "123",
-cipher => 'Blowfish',
-keysize => 128/8,
-header => 'salt'
);


This works with
openssl enc -bf-cbc -d -in /tmp/staging/passwd.gz.enc -out ah -pass pass:123


The same applies for other ciphers e.g
my $cipher = Crypt::CBC->new(
-key => "123",
-cipher => 'Rijndael',
-keysize => 128/8,
-header => 'salt'
);


This works with
openssl enc -aes-128-cbc -d -in /tmp/staging/passwd.gz.enc -out ah -pass pass:123


Inspiration from stackoverflow

No comments:

Post a Comment