Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CryptoAPI: Send a challenge to a smart card

CryptoAPI: Send a challenge to a smart card

Scheduled Pinned Locked Moved C / C++ / MFC
cryptographyhelpquestionlounge
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nyarlatotep
    wrote on last edited by
    #1

    Various smart card certificates are imported into the system store. When a smart card is inserted into the reader, the user have to select his certificate from the list of certificates in the sistem and then insert the PIN. To verify that the certificate selected from the system store correspond to the smart card currently in the reader I try to send a challenge to the smart card (GemPlus CSP) - A crypto context from the certificate selected from the system store is acquired. - A crypto context from the smart card in the reader is acquired. - A challenge is created with random data (CryptGenRandom()). - The public/private key pair is obtained from the certificate in the system. (CryptGetUserKey(AT_KEYEXCHANGE)). - The challenge is encrypted with the previous public key from the certificate in the system store (CryptEncrypt()). - The public/private key pair is obtained from the smart card (CryptGetUserKey(AT_KEYEXCHANGE)). - The encrypted challenge is decrypted with the smart card (CryptDecrypt(AT_KEYEXCHANGE)) which should use his private key. But when CryptDecrypt() with the crypto context of the smart card is called, error NTE_PROVIDER_DLL_FAIL (0x8009001D) is obtained. Where is the error ? NTE_PROVIDER_DLL_FAIL is an error raised when a context is acquired, according to the documentation, but it seems to have no relation with Crypt/Decrypt ! Thanks

    CPalliniC M 2 Replies Last reply
    0
    • N Nyarlatotep

      Various smart card certificates are imported into the system store. When a smart card is inserted into the reader, the user have to select his certificate from the list of certificates in the sistem and then insert the PIN. To verify that the certificate selected from the system store correspond to the smart card currently in the reader I try to send a challenge to the smart card (GemPlus CSP) - A crypto context from the certificate selected from the system store is acquired. - A crypto context from the smart card in the reader is acquired. - A challenge is created with random data (CryptGenRandom()). - The public/private key pair is obtained from the certificate in the system. (CryptGetUserKey(AT_KEYEXCHANGE)). - The challenge is encrypted with the previous public key from the certificate in the system store (CryptEncrypt()). - The public/private key pair is obtained from the smart card (CryptGetUserKey(AT_KEYEXCHANGE)). - The encrypted challenge is decrypted with the smart card (CryptDecrypt(AT_KEYEXCHANGE)) which should use his private key. But when CryptDecrypt() with the crypto context of the smart card is called, error NTE_PROVIDER_DLL_FAIL (0x8009001D) is obtained. Where is the error ? NTE_PROVIDER_DLL_FAIL is an error raised when a context is acquired, according to the documentation, but it seems to have no relation with Crypt/Decrypt ! Thanks

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      Regards to Cthulhu. :-D

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • N Nyarlatotep

        Various smart card certificates are imported into the system store. When a smart card is inserted into the reader, the user have to select his certificate from the list of certificates in the sistem and then insert the PIN. To verify that the certificate selected from the system store correspond to the smart card currently in the reader I try to send a challenge to the smart card (GemPlus CSP) - A crypto context from the certificate selected from the system store is acquired. - A crypto context from the smart card in the reader is acquired. - A challenge is created with random data (CryptGenRandom()). - The public/private key pair is obtained from the certificate in the system. (CryptGetUserKey(AT_KEYEXCHANGE)). - The challenge is encrypted with the previous public key from the certificate in the system store (CryptEncrypt()). - The public/private key pair is obtained from the smart card (CryptGetUserKey(AT_KEYEXCHANGE)). - The encrypted challenge is decrypted with the smart card (CryptDecrypt(AT_KEYEXCHANGE)) which should use his private key. But when CryptDecrypt() with the crypto context of the smart card is called, error NTE_PROVIDER_DLL_FAIL (0x8009001D) is obtained. Where is the error ? NTE_PROVIDER_DLL_FAIL is an error raised when a context is acquired, according to the documentation, but it seems to have no relation with Crypt/Decrypt ! Thanks

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Nyarlatotep wrote:

        Where is the error ?

        You tell us! :) From CryptAcquireContext(), CPAcquireContext(): NTE_PROVIDER_DLL_FAIL( 0x8009001DL ) The provider DLL file could not be loaded or failed to initialize.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        N 1 Reply Last reply
        0
        • M Mark Salsbery

          Nyarlatotep wrote:

          Where is the error ?

          You tell us! :) From CryptAcquireContext(), CPAcquireContext(): NTE_PROVIDER_DLL_FAIL( 0x8009001DL ) The provider DLL file could not be loaded or failed to initialize.

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          N Offline
          N Offline
          Nyarlatotep
          wrote on last edited by
          #4

          :) It could be but ... CryptAcquireContext() does not raise this error, it succeeded. It's CryptDecrypt() which fails. Naturally this function tries (would?) to decrypt data using the AT_KEYEXCHANGE key obtained with CryptGetUserKey() from the context acquired from the smart card. According to MSDN: "The CryptGetUserKey function retrieves a handle of one of a user's two public/private key pairs..." If I'm not wrong CryptoAPI CryptEncrypt()/CryptDecrypt() should use the public key to encrypt and the private key to decrypt, but decrypting with the private key from the smart card fails. Changhing the key type to AT_SIGNING when retrieving the key pair with CryptGetUserKey() has no effects (and it has not sense for me. I don't want to sign a piece of data with the private key. I want decrypt a piece of data with it ).

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups