encryption with blowfish
843811Dec 24 2007 — edited Dec 26 2007good morning to java experts
i am using blowfish algorithm for encryption so it can support key length 32-448 bits
following is the code for encryption:
package com.ack.security.jce;
import java.io.*;
import java.security.*;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.*;
import java.io.*;
public class BlowfishCipher {
public static void main(String[] args) throws Exception {
System.out.println("enter ur key");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String key=in.readLine();
String plainText="surendra";
KeyGenerator keygenerator = KeyGenerator.getInstance("Blowfish");
keygenerator.init(448);
SecretKey secretkey = keygenerator.generateKey();
byte[] raw=key.getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
// encrypt message
byte[] encrypted = cipher.doFinal(plainText.getBytes());
System.out.println(new String(encrypted));
System.exit(0);
}
}
output as follows:
enter ur key
1234567890qwertyu
Exception in thread "main" java.security.InvalidKeyException:illegal Key Size or default parameters
at javax.Crypto.Cipher.a(DashoA13*..)
at javax.Crypto.Cipher.a(DashoA13*..)
at javax.Crypto.Cipher.a(DashoA13*..)
at javax.Crypto.Cipher.init(DashoA13*..)
at javax.Crypto.Cipher.init(DashoA13*..)
at com.ack.security.jce.BlowfishCipher.main(BlowfishCipher.java:39)
the problem is that : it is working for key length 16 characters like 1234567890qwerty at command line but it is giving above error whenever it exceeds
plss reply as soon as possible
thanking you sir