0 Replies Latest reply: Dec 15, 2011 2:55 AM by 905506 RSS

    A bug with SunMSCAPI help Me

    905506
      I found a bug to level decryption when using the keystore in projet Applet,
      So I coded a simple function that does just encript / decript, but alas I still have the same bug;

      code:

      public static void seemsToWork(String tmp) throws Exception
      {
      KeyStore store = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
      store.load(null);
      String alias = "Eric";
      java.security.cert.Certificate cert = store.getCertificate(alias);
      PublicKey pubKey = (PublicKey) cert.getPublicKey();
      System.out.println("Public Key: "+pubKey.toString());
      PrivateKey privKey = (PrivateKey) store.getKey(alias, "nextmark".toCharArray());
      System.out.println("privKey Key: "+privKey.toString());
      Security.getProviders() ;
      Cipher ecipher = Cipher.getInstance("RSA","SunJCE");
      Cipher dcipher = Cipher.getInstance("RSA","SunMSCAPI");
      ecipher.init(Cipher.ENCRYPT_MODE, pubKey);
      byte [] messageBytes = tmp.getBytes("UTF-8");
      byte [] ciphertextBytes = ecipher.doFinal(messageBytes);
      System.out.println(new String (ciphertextBytes, "UTF-8"));
      dcipher.init(Cipher.DECRYPT_MODE, privKey);
      byte [] textBytes = dcipher.doFinal(ciphertextBytes);
      String decrypted = new String (textBytes, "UTF-8");
      System.out.println(decrypted);

      }
           
      Log :      
      Public Key: Sun RSA public key, 1024 bits
      modulus: 121390837807237222543846369009422054388485202447400366767468953556712054988239913146891087834759866184626378914739511497159698185436309183190569028716682188133349055246202485152466191578055319989664774327552155480071172644661179489275879368899119266761737909584784734319445591714474690033172878601460026086969
      public exponent: 65537
      privKey Key: RSAPrivateKey [size=1024 bits, type=Signature, container=b416d018-be00-9fd1-a2c3-6ee6b517ca15@GemP15-1]
      h?%??? ?I(?yw?:??N?yG???*e?p??z?:?f??1Z?y???oF?O?7??????9?u?
      \?o
      {??n8?m:???1?:???I?R????v?
      3??@?1????Y??
      Erreur : Erreur lors du decryptage
      java.security.ProviderException: java.security.KeyException: Une erreur interne s?est produite.

           at sun.security.mscapi.RSACipher.doFinal(RSACipher.java:277)
           at sun.security.mscapi.RSACipher.engineDoFinal(RSACipher.java:301)
           at javax.crypto.Cipher.doFinal(DashoA13*..)
           at klesign.objet.CryptageLogiciel.seemsToWork(CryptageLogiciel.java:158)
           at klesign.objet.CryptageLogiciel.decrypter(CryptageLogiciel.java:96)
           at klesign.Dechiffrer.run(Dechiffrer.java:57)
           at java.lang.Thread.run(Unknown Source)
      Caused by: java.security.KeyException: Une erreur interne s?est produite.

           at sun.security.mscapi.RSACipher.encryptDecrypt(Native Method)
           at sun.security.mscapi.RSACipher.doFinal(RSACipher.java:269)
           ... 6 more
           
      System : Windows XP , Windows 7

      usb Card : Gemplus USB Key Smart Card , Gemalto , Omnikey CardMan

      Thank's

      Edited by: 902503 on 15 déc. 2011 00:53

      Edited by: 902503 on 15 déc. 2011 00:54