hello all,
I am new to J2ME development rather this is my first code i have written in J2me for encryption and decryption using bouncycastle .
It is giving the error which i am unable to find solution for... plz help... :sad:
This is the error it is showing in netbeans
rror preverifying class javax.crypto.interfaces.DHPrivateKey
java/lang/IncompatibleClassChangeError: Implementing class
C:\Documents and Settings\Abhijeet.p\My Documents\NetBeansProjects\encryptText\nbproject\build-impl.xml:470: Preverification failed with error code 1.
BUILD FAILED (total time: 2 seconds)
and this is the code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import org.bouncycastle.crypto.CryptoException;
import org.bouncycastle.crypto.engines.DESedeEngine;
import org.bouncycastle.crypto.params.KeyParameter;
import org.bouncycastle.crypto.modes.CBCBlockCipher;
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.bouncycastle.util.encoders.Hex;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
* @author abhijeet.p
*/
public class EncryptText extends MIDlet implements CommandListener
{
private Display display; // Reference to Display object
private TextBox tbTest; // Main textbox
private Command cmExit; // Command to exit
private Command cmEncrypt; // Command to encrypt text
private Command cmDecrypt; // Command to decrypt text
private PaddedBufferedBlockCipher cipher = null; // The cipher
private String key = "x-392kla%3$*1f";
public EncryptText()
{
display = Display.getDisplay(this);
// Create the Commands.
cmExit = new Command("Exit", Command.EXIT, 1);
cmEncrypt = new Command("Encrypt", Command.SCREEN, 2);
cmDecrypt = new Command("Decrypt", Command.SCREEN, 3);
tbTest = new TextBox("Text to encrypt/decrypt",
"IBM developerworks", 250, TextField.ANY);
tbTest.addCommand(cmExit);
tbTest.addCommand(cmEncrypt);
tbTest.addCommand(cmDecrypt);
tbTest.setCommandListener(this);
// Create a new cipher (engine) for encrypting/decrypting
cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new DESedeEngine()));
// Create a key
key = new String("x-392kla%3$*1f");
}
public void startApp()
{
display.setCurrent(tbTest);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if (c == cmExit)
{
destroyApp(false);
notifyDestroyed();
}
else if (c == cmEncrypt) // Encrypt text
{
encryptData();
}
else if (c == cmDecrypt) // Decrypt text
{
decryptData();
}
}
private void encryptData()
{
// Get the contents from the textbox
// Get the contents from the textbox
byte[] inBytes = tbTest.getString().getBytes();
// Initialize the cipher. 'true' specifies encrypting
cipher.init(true, new KeyParameter(key.getBytes()));
// Determine the minimum output buffer size
byte[] outBytes = new byte[cipher.getOutputSize(inBytes.length)];
// 'len' is the actual size returned
int len = cipher.processBytes(inBytes, 0, inBytes.length, outBytes, 0);
try
{
// Process the last block in the buffer, starting at 'len' location
cipher.doFinal(outBytes, len);
tbTest.setString(new String(Hex.encode(outBytes)));
// Debug message
System.out.println("encrypted: " + new String(Hex.encode(outBytes)));
}
catch(CryptoException e)
{
System.out.println("Exception: " + e.toString());
}
}
private void decryptData()
{
// Get the text to decrypt from the textbox
// Get the text to decrypt from the textbox
byte[] inBytes = Hex.decode(tbTest.getString().getBytes());
// Initialize the cipher. 'false' specifies decrypting
cipher.init(false, new KeyParameter(key.getBytes()));
// Determine the minimum output buffer size
byte[] outBytes = new byte[cipher.getOutputSize(inBytes.length)];
// 'len' is the actual size returned
int len = cipher.processBytes(inBytes, 0, inBytes.length, outBytes, 0);
try
{
// Process the last block in the buffer, starting at 'len' location
cipher.doFinal(outBytes, len);
// Update the textbox with the decrypted string
tbTest.setString(new String(outBytes).trim());
System.out.println("decrypted: " + new String(outBytes).trim());
}
catch(CryptoException e)
{
System.out.println("Exception: " + e.toString());
}
}
}