Default CSP and GetLastError() (Encryption Problems)
-
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 -
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??? Thanksesapp420 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
-
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??? ThanksAnd 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
-
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
-
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??? ThanksOK, 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?? -
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?? -
I changed KEYLENGTH to NULL. This fixed the problem, but I dont know why, or if this is the best way.
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