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 question

CryptoAPI question

Scheduled Pinned Locked Moved C / C++ / MFC
comgraphicssecurityhelpquestion
6 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I used CryptAcquireContext with MS_ENHANCED_PROV and then created an RC4 key. I want to export this key without any encryption. I tried using PLAINTEXTBLOB on CryptExportKey. It works fine on XP, but fails on 2000 (with Enhanced Provider installed) with error NTE_BADKEY. m_sessionkey is valid at that point. I can export it using my public key. The line of code: if (!CryptExportKey(m_sessionkey, 0, PLAINTEXTKEYBLOB, 0, NULL, &length)) { DWORD dwErr = GetLastError(); LogError(dwErr); return false; } std::vector<BYTE > keydata; keydata.resize(length); if (!CryptExportKey(m_sessionkey, 0, PLAINTEXTKEYBLOB, 0, &keydata[0], &length)) { DWORD dwErr = GetLastError(); LogError(dwErr); return false; } My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

    G R 2 Replies Last reply
    0
    • L Lost User

      I used CryptAcquireContext with MS_ENHANCED_PROV and then created an RC4 key. I want to export this key without any encryption. I tried using PLAINTEXTBLOB on CryptExportKey. It works fine on XP, but fails on 2000 (with Enhanced Provider installed) with error NTE_BADKEY. m_sessionkey is valid at that point. I can export it using my public key. The line of code: if (!CryptExportKey(m_sessionkey, 0, PLAINTEXTKEYBLOB, 0, NULL, &length)) { DWORD dwErr = GetLastError(); LogError(dwErr); return false; } std::vector<BYTE > keydata; keydata.resize(length); if (!CryptExportKey(m_sessionkey, 0, PLAINTEXTKEYBLOB, 0, &keydata[0], &length)) { DWORD dwErr = GetLastError(); LogError(dwErr); return false; } My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

      G Offline
      G Offline
      geo_m
      wrote on last edited by
      #2

      not being an expert with microsoft's cryptoapi I would check if the key is generated with Exportable flag. Might be also the Q228786 will be usefull for you. Don't have any more clue with great microsoft's CryptoAPI X|

      L 1 Reply Last reply
      0
      • G geo_m

        not being an expert with microsoft's cryptoapi I would check if the key is generated with Exportable flag. Might be also the Q228786 will be usefull for you. Don't have any more clue with great microsoft's CryptoAPI X|

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Thank you. But the issue is the same executable works on XP, and not on 2000. The docs does not mention any XP dependency. ... and ofcourse, the key is exportable. Thomas My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

        G 1 Reply Last reply
        0
        • L Lost User

          Thank you. But the issue is the same executable works on XP, and not on 2000. The docs does not mention any XP dependency. ... and ofcourse, the key is exportable. Thomas My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

          G Offline
          G Offline
          geo_m
          wrote on last edited by
          #4

          I understand, but having no idea what was changed in XP crypto provider. Might be some small change, don't know. Can it be a question of service pack installed in W2K?

          1 Reply Last reply
          0
          • L Lost User

            I used CryptAcquireContext with MS_ENHANCED_PROV and then created an RC4 key. I want to export this key without any encryption. I tried using PLAINTEXTBLOB on CryptExportKey. It works fine on XP, but fails on 2000 (with Enhanced Provider installed) with error NTE_BADKEY. m_sessionkey is valid at that point. I can export it using my public key. The line of code: if (!CryptExportKey(m_sessionkey, 0, PLAINTEXTKEYBLOB, 0, NULL, &length)) { DWORD dwErr = GetLastError(); LogError(dwErr); return false; } std::vector<BYTE > keydata; keydata.resize(length); if (!CryptExportKey(m_sessionkey, 0, PLAINTEXTKEYBLOB, 0, &keydata[0], &length)) { DWORD dwErr = GetLastError(); LogError(dwErr); return false; } My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

            R Offline
            R Offline
            Raphael Amorim
            wrote on last edited by
            #5

            If you want the key value try this article: http://www.codeproject.com/cpp/plaintextsessionkey.asp Raphael Amorim Dantas Leite VC++, VB, Java, .NET and eMbedded Programmer

            L 1 Reply Last reply
            0
            • R Raphael Amorim

              If you want the key value try this article: http://www.codeproject.com/cpp/plaintextsessionkey.asp Raphael Amorim Dantas Leite VC++, VB, Java, .NET and eMbedded Programmer

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Thank you very much :-) My article on a reference-counted smart pointer that supports polymorphic objects and raw pointers

              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