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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

javax.crypto.BadPaddingException:Given final block not properly padded

843811Dec 27 2007 — edited Dec 27 2007
a very good morning to all cryptography experts

sir,
i am getting problem while decryption with blowfish algorthim

my code as follows:

package com.ack.security.jce;

import java.lang.String.*;
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);
// create a key
SecretKey secretkey = keygenerator.generateKey();
byte[] raw=key.getBytes();
SecretKeySpec skeySpec = new SecretKeySpec(raw, "Blowfish");
// create a cipher based upon Blowfish
Cipher cipher = Cipher.getInstance("Blowfish");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
// decrypt message
byte[] decrypted = cipher.doFinal(plainText.getBytes());
System.out.println(new String(decrypted));
System.exit(0);
}
}

OUTPUT:

enter ur key: jan
Exception in thread "main" javax.crypto.BadPaddingException:Given final block not properly padded
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.BlofishCipher.engineDoFinal(DashoA13*..)
at com.sun.crypto.doFinal(DashoA13*..)
at com.ack.security.jce.BlofishCipher.main(BlowfishCipher.java:27)


the above exceptions coming

plss help me as soon as possible
thanking u sir
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 24 2008
Added on Dec 27 2007
5 comments
1,275 views