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. Default CSP and GetLastError() (Encryption Problems)

Default CSP and GetLastError() (Encryption Problems)

Scheduled Pinned Locked Moved C / C++ / MFC
helpsecuritybeta-testingquestion
7 Posts 2 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.
  • E Offline
    E Offline
    esapp420
    wrote on last edited by
    #1

    Hello, I posted on this yesterday, but I am still having trouble. I am using this code: // Get handle to the default provider. if(!CryptAcquireContext(&hCryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0)) { HandleError("Error during CryptAcquireContext."); return -4; } to aquire a handle to the Default CSP. Handle error goes like this: void CFPCommonFunctions::HandleError(CString strFunction) { CString strMsg; strMsg.Format("CFPCommonFunctions::EncryptTransFile() - %s: %u.", strFunction, GetLastError()); AfxMessageBox(strMsg, MB_OK | MB_ICONEXCLAMATION); } which returns the error 80090019 (I dont think this is formatted correctly by my function because I cant find this error in the Windows list) I have no problems on my Win2000 machine, nor do I have a problem on my Win98 machine that has VS6 installed. My beta users are getting this error every time, and when I try it on a fresh Win95 OSR2 install I get the error as well. MSDN says this is compatible with Win95 OSR2 and later. Can anybody see where I am going wrong??? Thanks

    M E 3 Replies Last reply
    0
    • E esapp420

      Hello, I posted on this yesterday, but I am still having trouble. I am using this code: // Get handle to the default provider. if(!CryptAcquireContext(&hCryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0)) { HandleError("Error during CryptAcquireContext."); return -4; } to aquire a handle to the Default CSP. Handle error goes like this: void CFPCommonFunctions::HandleError(CString strFunction) { CString strMsg; strMsg.Format("CFPCommonFunctions::EncryptTransFile() - %s: %u.", strFunction, GetLastError()); AfxMessageBox(strMsg, MB_OK | MB_ICONEXCLAMATION); } which returns the error 80090019 (I dont think this is formatted correctly by my function because I cant find this error in the Windows list) I have no problems on my Win2000 machine, nor do I have a problem on my Win98 machine that has VS6 installed. My beta users are getting this error every time, and when I try it on a fresh Win95 OSR2 install I get the error as well. MSDN says this is compatible with Win95 OSR2 and later. Can anybody see where I am going wrong??? Thanks

      M Offline
      M Offline
      Martin Ziacek
      wrote on last edited by
      #2

      esapp420 wrote: which returns the error 80090019 This error means: 'The keyset is not defined.' By default CryptAcquireContext() will use keyset based on the user name and it does not exist automatically. Therefore your very first call on the new machine should contain CRYPT_NEWKEYSET within the flags. I would also recommend to check if there is required provider installed on the target machine. Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

      1 Reply Last reply
      0
      • E esapp420

        Hello, I posted on this yesterday, but I am still having trouble. I am using this code: // Get handle to the default provider. if(!CryptAcquireContext(&hCryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0)) { HandleError("Error during CryptAcquireContext."); return -4; } to aquire a handle to the Default CSP. Handle error goes like this: void CFPCommonFunctions::HandleError(CString strFunction) { CString strMsg; strMsg.Format("CFPCommonFunctions::EncryptTransFile() - %s: %u.", strFunction, GetLastError()); AfxMessageBox(strMsg, MB_OK | MB_ICONEXCLAMATION); } which returns the error 80090019 (I dont think this is formatted correctly by my function because I cant find this error in the Windows list) I have no problems on my Win2000 machine, nor do I have a problem on my Win98 machine that has VS6 installed. My beta users are getting this error every time, and when I try it on a fresh Win95 OSR2 install I get the error as well. MSDN says this is compatible with Win95 OSR2 and later. Can anybody see where I am going wrong??? Thanks

        M Offline
        M Offline
        Martin Ziacek
        wrote on last edited by
        #3

        And another thing, here is the Mailing List Archives of CryptoAPI@DISCUSS.MICROSOFT.COM where you can more information specific to CAPI than here. Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

        E 1 Reply Last reply
        0
        • M Martin Ziacek

          And another thing, here is the Mailing List Archives of CryptoAPI@DISCUSS.MICROSOFT.COM where you can more information specific to CAPI than here. Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

          E Offline
          E Offline
          esapp420
          wrote on last edited by
          #4

          Thank you! This is exactly what I was looking for. Miami is going down! 08/07/2002 Welcome to the SWAMP baby!

          1 Reply Last reply
          0
          • E esapp420

            Hello, I posted on this yesterday, but I am still having trouble. I am using this code: // Get handle to the default provider. if(!CryptAcquireContext(&hCryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0)) { HandleError("Error during CryptAcquireContext."); return -4; } to aquire a handle to the Default CSP. Handle error goes like this: void CFPCommonFunctions::HandleError(CString strFunction) { CString strMsg; strMsg.Format("CFPCommonFunctions::EncryptTransFile() - %s: %u.", strFunction, GetLastError()); AfxMessageBox(strMsg, MB_OK | MB_ICONEXCLAMATION); } which returns the error 80090019 (I dont think this is formatted correctly by my function because I cant find this error in the Windows list) I have no problems on my Win2000 machine, nor do I have a problem on my Win98 machine that has VS6 installed. My beta users are getting this error every time, and when I try it on a fresh Win95 OSR2 install I get the error as well. MSDN says this is compatible with Win95 OSR2 and later. Can anybody see where I am going wrong??? Thanks

            E Offline
            E Offline
            esapp420
            wrote on last edited by
            #5

            OK, things are going better, but still having trouble. After modifying my code in accordance with the above mentioned advice, I no longer have a problem with CryptAquireContext. Now I have a problem with this: // Derive a session key from the hash object. if(!CryptDeriveKey(hCryptProv, ENCRYPT_ALGORITHM, hHash, KEYLENGTH, &hKey)) { HandleError("Error during CryptDeriveKey."); return -7; } returning error 2148073481 (Invalid Flags Specified). The only Flag param is the 4th. KEYLENGTH is defined as 0x00800000 at the top of my file for 128-bit encription key, and ENCRYPT_ALGORITHM is defined as CALG_RC4. I am giving it a valid hCryptProv and a valid hHash. wincrypt.h defines only on flag under the section for CryptDeriveKey (KEY_LENGTH_MASK 0xFFFF0000). I am new to the CryptoAPI and cant see what I am doing wrong. Martin?? Anyone??

            E 1 Reply Last reply
            0
            • E esapp420

              OK, things are going better, but still having trouble. After modifying my code in accordance with the above mentioned advice, I no longer have a problem with CryptAquireContext. Now I have a problem with this: // Derive a session key from the hash object. if(!CryptDeriveKey(hCryptProv, ENCRYPT_ALGORITHM, hHash, KEYLENGTH, &hKey)) { HandleError("Error during CryptDeriveKey."); return -7; } returning error 2148073481 (Invalid Flags Specified). The only Flag param is the 4th. KEYLENGTH is defined as 0x00800000 at the top of my file for 128-bit encription key, and ENCRYPT_ALGORITHM is defined as CALG_RC4. I am giving it a valid hCryptProv and a valid hHash. wincrypt.h defines only on flag under the section for CryptDeriveKey (KEY_LENGTH_MASK 0xFFFF0000). I am new to the CryptoAPI and cant see what I am doing wrong. Martin?? Anyone??

              E Offline
              E Offline
              esapp420
              wrote on last edited by
              #6

              I changed KEYLENGTH to NULL. This fixed the problem, but I dont know why, or if this is the best way.

              M 1 Reply Last reply
              0
              • E esapp420

                I changed KEYLENGTH to NULL. This fixed the problem, but I dont know why, or if this is the best way.

                M Offline
                M Offline
                Martin Ziacek
                wrote on last edited by
                #7

                There were several versions of CSPs published by Microsoft. Check documentation for CryptDeriveKey() and assure that you are requesting key length supported by CSP or you are using right CSP. I think, if you will ask for a longer key than maximum length, it will refuse it with invalid flag error. Martin -------------------------------------------- C'mon we all know computers are experimental devices and should only be used for playing games. Using them for alternative stuff like business, is clearly not using them for what they are intended. Colin Davies

                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