Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Blowfish how to set key length and password

843810Dec 24 2002 — edited Dec 28 2002
Hi,
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 25 2003
Added on Dec 24 2002
2 comments
362 views