use Crypt::CBC;
my $crypt = Crypt::CBC->new(-key => "password", -cipher => "Crypt::Blowfish");
print $crypt->encrypt_hex('s');
How do I get the same result using java?
Thanks in Advance.
use Crypt::CBC;
my $crypt = Crypt::CBC->new(-key => "password", -cipher => "Crypt::Blowfish");
print $crypt->encrypt_hex('s');
How do I get the same result using java?
Thanks in Advance.
You can use the javax.crypto package. Although this isn't a solution, it should get you on the right track:
// encrypt
byte[] key = "password".getBytes("US-ASCII");
byte[] plaintext = "s".getBytes("US-ASCII");
SecretKeySpec skeySpec = new SecretKeySpec(key, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
// show result
byte[] result = cipher.doFinal(plaintext);
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < result.length; i++) {
String hex = Integer.toHexString(0xFF & result[i]);
if (hex.length() == 1) {
hexString.append('0');
}
hexString.append(hex);
}
System.out.println(hexString);
This should solve everything except for the randomly generated salt.