Hi, I'm doing a program that sends and receives message using SIP.
I want to generate key pair for this program as i need the key pair to create certificates.

I'm able to found key pair generation codes, but however when i call the key pair generated into the MIDlet, the respective function cannot be run

I think it has something to do with "ClassNotFoundException".

My key pair generation code:

public PublicKey getPublicKey() throws Exception{

        Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
        KeyPairGenerator keyGenerator = KeyPairGenerator.getInstance("DSA");
        SecureRandom rng = SecureRandom.getInstance("SHA1PRNG", "SUN");
        keyGenerator.initialize(1024, rng);
        KeyPair kp = keyGenerator.generateKeyPair();
        PublicKey pubKey = kp.getPublic();
        return pubKey;

As for the sending and receiving message, it is more or less same as the SIP demo provided by Java ME.

Can someone point me the correct way of making this works? :)


9 Years
Discussion Span
Last Post by keofua

It has nothing to do with that code you posted. Did you imported all libraries as required?
In the future please post whole error not just part of it...


The errors rise when i try to access the list that runs the key generate functions. Below are the errors.

java.lang.NoClassDefFoundError: java/security/KeyPairGenerator: Cannot create class in system package
at KeyGenerator.generateKeys(KeyGenerator.java:10)
at SIPDemo.composeMessage(SIPDemo.java:59)
at SIPDemo.commandAction(SIPDemo.java:113)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(Display.java:2093)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(Display.java:2929)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(DefaultEventHandler.java:297)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(AutomatedEventHandler.java:667)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(DefaultEventHandler.java:711)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(DefaultEventHandler.java:608)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.