i have completed the encryption part of this but am struggling with the decrypt part.....the gui enables the user to select a txt file from a location for either encryption or decryption!!!but for the decryption part im recieving a badPaddingException: Block type mismatch...can anyone help please,would appreciate it greatly as it is a very important project.
here is my code so far.......


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.security.*;
import javax.crypto.*;
import java.math.BigInteger;
import sun.misc.*;


public class RunCrypto1
{

public static void main(String[] args)
{

JFrame frame = new JFrame();
frame.setTitle("Cryptotron");
FileHandler fh = new FileHandler(frame);
frame.setSize(500,300);
frame.getContentPane().add(fh);
frame.setVisible(true);
}
}
class FileHandler extends JPanel implements ActionListener
{

File f;

private JFrame associatedFrame;
private JTextArea viewArea = new JTextArea(8,40);

private JMenuBar bar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private JMenu quitMenu = new JMenu("Quit");
private JMenuItem selectChoice = new JMenuItem("Select");
private JMenuItem reallyQuitChoice = new JMenuItem("Exit");
private JMenuItem cancelChoice = new JMenuItem("Cancel");

private JPanel buttonPanel = new JPanel();

private JButton Encrypt = new JButton("Encrypt");
private JButton Decrypt = new JButton("Decrypt");


private String selectedFile = null;
private String dir = null;

public FileHandler(JFrame frameIn)
{
associatedFrame = frameIn;
add(viewArea);

bar.add(fileMenu);
bar.add(quitMenu);

fileMenu.add(selectChoice);
quitMenu.add(reallyQuitChoice);
quitMenu.add(cancelChoice);

frameIn.setJMenuBar(bar);

Encrypt.addActionListener(this);
Decrypt.addActionListener(this);

buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER,10,20));
buttonPanel.add(Encrypt);
buttonPanel.add(Decrypt);

add(buttonPanel, "South");

selectChoice.addActionListener(this);
reallyQuitChoice.addActionListener(this);
cancelChoice.addActionListener(this);


}


public void actionPerformed(ActionEvent e)
{
if(e.getSource() == selectChoice)
{
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
jfc.setMultiSelectionEnabled(false);
int status = jfc.showOpenDialog(this);

if(status == JFileChooser.APPROVE_OPTION)
{
System.out.println("File Choosen : " + jfc.getSelectedFile().getName());
f = jfc.getSelectedFile();

}

viewArea.append("Selected File: " + f + '\n');
}

if(e.getSource() == reallyQuitChoice)
{
System.exit(0);
}
if(e.getSource()==cancelChoice)
{
viewArea.append("Quit option cancelled \n" );
}

if(e.getSource()==Encrypt)
{
try
{

viewArea.append("Start Encryption \n" );
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(1024);
KeyPair key = keyGen.generateKeyPair();
PublicKey pub = key.getPublic();
viewArea.append(". \n" );

Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, pub);

BufferedReader fs = new BufferedReader(new FileReader(f));
String oldFileName = f.getName();
String aLine = "";
String something = "";
while(null != (aLine = fs.readLine()))
{
aLine = something;
System.out.println(something);
}


fs.close();

byte [] cleartext = null;
cleartext = something.getBytes();
viewArea.append(". \n" );

byte[] ciphertext = null;
ciphertext = cipher.doFinal(cleartext);
f.delete();

f = new File(oldFileName);
BufferedWriter os = new BufferedWriter(new FileWriter(f));
os.write("" + ciphertext);
viewArea.append("File "+ f + " has been Encrypted \n");
viewArea.append(". \n" );
viewArea.append(". \n" );
os.close();


}
/*catch( IllegalStateException err)

{
System.out.println("dsafdsfdsf");
System.exit(0);
}*/


catch ( Exception er)
{
er.printStackTrace();
System.out.println("error..................");
}


}


if(e.getSource()==Decrypt)
{
try
{

viewArea.append("Start Decryption \n");
KeyPairGenerator keyGen2 = KeyPairGenerator.getInstance("RSA");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen2.initialize(1024);
KeyPair key2 = keyGen2.generateKeyPair();
PrivateKey priv = key2.getPrivate();



Cipher cipher2 = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher2.init(Cipher.DECRYPT_MODE, priv);


BufferedReader zz = new BufferedReader(new FileReader(f));
String oldFileName2 = f.getName();
String aLine2 = "";
String something2 = "";
while(null != (aLine2 = zz.readLine()))
{
aLine2 = something2;
System.out.println(something2);
}


zz.close();

byte [] `ciphertext2 = null;
ciphertext2 = something2.getBytes();

byte[] cleartext2 = null;
cleartext2 = cipher2.doFinal(ciphertext2);
f.delete();

f = new File(oldFileName2);
BufferedWriter os2 = new BufferedWriter(new FileWriter(f));
os2.write("" + cleartext2);
viewArea.append("File Decrypted \n");
os2.close();





}
catch ( Exception er)
{
er.printStackTrace();
System.out.println("error..................");
}
}


}
}