I'm running Windows Server 2k8 (maybe that's half the problem?) Anyway, I'm getting different values out of different Blowfish modules in various languages. Is there one which can be relied upon as the standard?
For the following examples, assume the key is password
and the plaintext 12345678
.
a. The Online Encrypt Tool with Algorithm set to Blowfish
mode ECB
and Base64 Encode the output
checked gives 2mADZkZR0VM=
. I've been using this a my reference point, wise or otherwise.
b. The following Perl code uses Crypt::ECB
and MIME::Base64
use MIME::Base64;
use Crypt::ECB;
$crypt = Crypt::ECB->new;
$crypt->padding(PADDING_NONE);
$crypt->cipher('Blowfish') || die $crypt->errstring;
$crypt->key('password');
$enc = $crypt->encrypt("12345678");
print encode_base64($enc);
This outputs 2mADZkZR0VM=
with PADDING_NONE (which compares well with 'a.' above). However, when padding is set to PADDING_AUTO
it outputs 2mADZkZR0VOZ5o+S6D3OZw==
which is, in my mind at least, a bug as the plaintext is 8 characters long and in no need of padding.
c. If I use Crypt::Blowfish
as below
#! c:\perl\bin
use Crypt::Blowfish;
use MIME::Base64;
my $key;
my $plaintext;
$key = "password";
$plaintext = "12345678";
my $cipher = new Crypt::Blowfish $key;
my $ciphertext = $cipher->encrypt($plaintext);
my $encoded = encode_base64( $ciphertext );
print $encoded;
then I get 2mADZkZR0VM=
which matches 'a.' above. Trouble with this module though is that one has to segment things into 8 byte chunks for encoding; it has no chunker of its own.
d. If I use the source at http://linux.die.net/man/3/bf_ecb_encrypt (which I did for a recent PHP ext project) then I get the same answer as 'a.'. I'm inclined to trust this code the most as it's in use in SSLeay and OpenSSL.
e. The BlowfishEx.EXE
in DI Management's Blowfish: a Visual Basic version with PKCS#5
padding gives 2mADZkZR0VOZ5o+S6D3OZw==
which is the same as the Crypt::ECB results with PADDING_AUTO
. With Padding set to None
I get 2mADZkZR0VM=
which matches 'a.'
I've partly answered my own question writing this: looks like I just have to modify DI Management's code for the VB6 project. And maybe suggest the same to the writer of Crypt::ECB.
But the question remains: is there a trustworthy blowfish reference platform?