Forum Stats

  • 3,815,605 Users
  • 2,259,059 Discussions
  • 7,893,185 Comments

Discussions

getInstance method

5f377c77-ba0c-40d5-8971-0eda91610ca0
edited Mar 26, 2018 8:22AM in Java Card

I would like to know if the following classes are singleton.

javacard.security.MessageDigest
javacard.security.InitializedMessageDigest
javacard.security.Signature
javacard.security.RandomData
javacard.security.KeyAgreement
javacard.security.Checksum
javacardx.crypto.Cipher

I have to create always a new object with the getInstance method????

Thanks in advance.

Answers

  • PhHein
    PhHein Member, Moderator Posts: 7,228 Silver Trophy
    edited Mar 23, 2018 5:03AM

    Hi,

    have a look at the API docs: https://docs.oracle.com/javacard/3.0.5/api/javacard/security/package-summary.html

    MesageDigest, for example, only has a protected construstor. In that case getInstance(...) is your only chance.

  • patrick.vh-Oracle
    patrick.vh-Oracle Member Posts: 18 Employee
    edited Mar 26, 2018 8:22AM

    Hi,


    These classes are not singleton for several reasons:
    - these are stateful classes that contain the current state of an on-going operation. In particular, the update() method may accumulate data in an internal buffer before processing it.
    - several application on the platform may need to perform the same operation at the same time so each need to use its own independent instance.


    However, an application can get an instance and store it in a persistent field (e.g. in the Applet.install() method) then re-use it several times (e.g. in Applet.process() method)

    Patrick

This discussion has been closed.