Blowfish how to set key length and password
843810Dec 24 2002 — edited Dec 28 2002Hi,
I am new to using the JCE. How does one use a password and set the keylength in Blowfish. I would like to use a keylength of at least 128, and the passwords are being picked up without the user being aware.
So in this code sample how do I get a key of 128 not the default 56, and how do you check that??
try {
String password="to easy to guess";
SecretKeySpec spec= new SecretKeySpec(password.getBytes(),"Blowfish");
System.out.println("key done password");
byte[] raw = spec.getEncoded();
System.out.println("Encoded " + Blow.toHexString(raw));
System.out.println("Format " + spec.getFormat());
System.out.println("Algorithm " + spec.getAlgorithm());
//SecretKeySpec skeySpec = new SecretKeySpec(raw, "Blowfish");
Cipher fileCipher = Cipher.getInstance("Blowfish");
fileCipher.init(Cipher.ENCRYPT_MODE, spec);
byte[] encrypted = fileCipher.doFinal("This is just an example".getBytes());
System.out.println(Blow.toHexString(encrypted));
fileCipher.init(Cipher.DECRYPT_MODE,spec);
byte[] out = fileCipher.doFinal(encrypted);
System.out.println(Blow.toHexString(out));
System.out.println( new String(out));
}
catch (Exception e) {
System.err.println("Exception: " + e.toString());
}
}
Thanks
Howie