0 Replies Latest reply: Oct 22, 2009 9:46 AM by 843851 RSS

    javax.crypto.* and javax.crypto.spec.* problem with MHP receiver

      Hello to everyone, I started to program in MHP 1.0.2 on a MHP receiver and now i'm practicing in encrypting and decrypting. I load from the smart card in the MHP receiver an X509Certificate object (I have it both in byte[] form, called certArray, and X509Certificate object, called "certificate"). What i'd like to do is to :

      1)calculate digest of the certificate (line 1 and 2 of the following code)
      2) encrypt the digest using the same algorithm of the certificate (see line 3 and 4)

      The problem is generated at line 3 : the receiver, probably, doesn't find the class of the algorithm of encrypting. It is important to notice that the instruments to encrypt/decrypt are included in javax.crypto and javax.crypto.spec packages.

      MessageDigest md = MessageDigest.getInstance("SHA");
      byte[] digest = md.digest(certArray);
      Cipher encrypt = Cipher.getInstance(certificate.getSigAlgName());
      encrypt.init(Cipher.ENCRYPT_MODE, certificate.getPublicKey());

      The error message, in the log file, is the following :

      [0#1:2] java.security.NoSuchAlgorithmException: SHA1withRSA not found
           [0#1:2]      at javax.crypto.Cipher.getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;(Unknown Source)
           [0#1:2]      at it.csp.SecurelabXlet.encrypt()V(Unknown Source)
           [0#1:2]      at it.csp.SecurelabXlet.cardInserted(Lopencard/core/event/CardTerminalEvent;)V(Unknown Source)
           [0#1:2]      at opencard.core.event.EventGenerator.createEventsForPresentCards(Lopencard/core/event/CTListener;)V(Unknown Source)
           [0#1:2]      at it.csp.SecurelabXlet.register()V(Unknown Source)
           [0#1:2]      at it.csp.SecurelabXlet.startXlet()V(Unknown Source)
           [0#1:2]      at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
           [0#1:2]      at tv.osmosys.application.AppManager$XletApp.xletStart()Z(Unknown Source)
           [0#1:2]      at tv.osmosys.application.AppManager$XletApp.loop0(Ltv/osmosys/application/AppManager$XletAction;)V(Unknown Source)
           [0#1:2]      at tv.osmosys.application.AppManager$XletApp.run()V(Unknown Source)
           [0#1:2]      at java.lang.Thread.run()V(Unknown Source)
           [0#1:2]      at java.lang.Thread.startup(Z)V(Unknown Source)

      My question(s) is : how can I include javax.crypto and javax.crypto.spec in the Xlet application to upload it onto the MHP receiver?? Is it possibile to do so?
      Eventually, do other libraries exist to use encrypting algorithms, included in MHP? The version I use of MHP is 1.0.2. Thank you! Bye!