Example: Creating digital signatures

This example demonstrates how to use a smart card (for example, the SIM card) to digitally sign data, it implements the PKI API in the Security and Trust Services API 1.0 defined in JSR-177.

Note: This example only shows how to digitally sign data, not to receive or authenticate these signatures.

The application demonstrates how to:

  1. Create a text field for entering the text to be signed.

    A default text "ToBeSigned" is suggested when you open the application. The maximum length of the field is 100 characters.

  2. Choose an appropriate signing option from the Options list.

    The options available are:

    • AuthenSignByteHasContent for signing Byte data for authentication purposes including content

    • AuthenSignByteNoContent for signing Byte data for authentication purposes excluding content

    • AuthenSignStringHasContent for signing String data for authentication purposes including content

    • AuthenSignStringNoContent for signing String data for authentication purposes excluding content

    • CMSWithContent for creating a CMS formatted signature including content

    • CMSNoContent for creating a CMS formatted signature excluding content

  3. Search for a certificate stored on the smart card of your device. Note that your PIN is automatically asked when accessing the smart card.

  4. Generate a signed data package or a signature using the certificate. When the signing is finished, you can see a message on the screen saying "Already signed".

Figure 107: Basic user interface of PKI MIDlet