×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    58

    How to implement Digital Signature in J2ME

    What i want to do is :

    1) Install digital signed testing certificate in my mobile device (using S60).

    2) Create a SMS sending form in midlet.

    3) Digitally signed the information using installed certificate before sending via SMS sending form.

    How would do this??

    What i've done till:

    1) I've installed a certificate from this link http://www.aloaha.com/wi-software-en/aloaha-pki.php.

    2) I used following midlet as example:

    Code:
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.securityservice.CMSMessageSignatureService;
    import javax.microedition.securityservice.CMSMessageSignatureServiceException;
    import javax.microedition.io.file.FileConnection;
    import javax.microedition.io.file.FileSystemRegistry;
    import java.io.OutputStream;
    import java.util.Enumeration;
    import javax.microedition.io.Connector;
    
    public class PaymentAuthorization extends MIDlet implements CommandListener {
    
        Display display = null;
        List employeeList = null;
        String[] employeeArray = {"Derrick Johnson, 40 hrs", "James Williams, 44 hrs", "Tirrell Payton, 42 hrs", "William Bean, 20 hrs"};
        Form progressForm = null;
        Command authCommand = null;
        Command denyCommand = null;
        Command exitCommand = null;
        String originalMessage = null;
        byte[] signedMessage = null;
        String signedMessageFile = "paymentAuthorization.dat";
    
        public PaymentAuthorization(){
            employeeList = new List("Payment Authorization", List.IMPLICIT, employeeArray, null);
            employeeList.setCommandListener(this);
            authCommand = new Command("Authorize", Command.OK, 0);
            denyCommand = new Command("Deny", Command.OK, 0);
            exitCommand = new Command("Exit", Command.EXIT, 1);
            employeeList.addCommand(authCommand);
            employeeList.addCommand(denyCommand);
            progressForm = new Form("Signing Progress");
            progressForm.addCommand(exitCommand);
            progressForm.setCommandListener(this);
        }
    
        public void startApp() {
            display = Display.getDisplay(this);
            display.setCurrent(employeeList);
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
        }
    
        public void commandAction(Command command, Displayable d) {
            if (command == exitCommand) {
                destroyApp(true);
                notifyDestroyed();
            } else {
    
                display.setCurrent(progressForm);
                originalMessage = employeeArray[employeeList.getSelectedIndex()] + ", " + command.getLabel();
    
                new Thread() {
                        public void run() {
                            progressForm.append("Sign test started ...\n");
                            System.out.println("Sign test started...");
                            signMessage();
                            progressForm.append("Sign test finished.\n");
                            System.out.println("Sign test finished.");
                        }
               }.start();
            }
    
        }
    
        private void signMessage() {       
            String caName = "c=US,o=Aloaha Certification Authority,cn=Aloaha Certification Authority";
            String[] caNames = new String[1];
            String userPrompt = "Please insert the proper security element ";
            caNames[0] = caName;
            try {            
                signedMessage = CMSMessageSignatureService.sign(originalMessage,CMSMessageSignatureService.SIG_INCLUDE_CERTIFICATE | CMSMessageSignatureService.SIG_INCLUDE_CONTENT, caNames, userPrompt);
               
                FileConnection fileConnection = null;
                OutputStream outputStream = null;
                try{
                    Enumeration e = FileSystemRegistry.listRoots();
                    String rootName = (String) e.nextElement ();
                    String galleryPath = System.getProperty("fileconn.dir.photos");
                    fileConnection = (FileConnection)Connector.open(galleryPath + signedMessageFile);
                    if (fileConnection.exists() == false){
                        fileConnection.create();
                    }
                    outputStream = fileConnection.openOutputStream();
                    outputStream.write(signedMessage);
                    outputStream.flush();
                    outputStream.close();
                    fileConnection.close();
                } catch (Exception e){
                    System.out.println("Error creating file");
                    e.printStackTrace();
                }
    
            } catch (IllegalArgumentException iae) {
                // Perform error handling
                iae.printStackTrace();
            } catch (CMSMessageSignatureServiceException ce) {
                if (ce.getReason() == CMSMessageSignatureServiceException.CRYPTO_FORMAT_ERROR) {
                    System.out.println("Error formatting signature.");
                } else {
                    System.out.println(ce.getMessage());
                }
            } catch (Exception e) {
                System.out.println("Other exception: " + e);
            }
        }
    }
    3) While running this midlet. I'm unable to create .dat file. Even, file connection code is not executing.. as it is not showing any security exception regading file connection.


    Thanks!!!
    Last edited by jayantb; 2011-12-14 at 13:39.

Similar Threads

  1. Digital Signature in J2ME
    By jayantb in forum Mobile Java General
    Replies: 3
    Last Post: 2011-12-14, 13:41
  2. Replies: 0
    Last Post: 2011-04-03, 17:08
  3. Problem with Digital signature
    By celmon in forum Mobile Java General
    Replies: 3
    Last Post: 2007-04-02, 11:24
  4. How to obtain a digital signature?
    By davidevit in forum Mobile Java General
    Replies: 0
    Last Post: 2003-11-25, 15:14
  5. What is a digital signature?
    By Nokia_FAQ in forum Mobile Commerce
    Replies: 1
    Last Post: 2002-05-15, 15:44

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×