By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

CryptGetUserKey works in WinXP but fails in Win2000

P: n/a
Does anyone have any ideas about why the Crypto API call to
CryptGetUserKey()would work just fine in WindowsXP but fails when
executed in Windows2000? The call is made in code that is practically
identical to the well known file encryption example found in the MSDN
help (see ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/security/security/example_c_program_encrypting_a_file.htm
if you have MSDN installed on your machine) and attempts to use the
AT_KEYEXCHANGE private key from the key container. GetLastError() is
returning NTE_NO_KEY signifying that "The key requested by the
dwKeySpec parameter does not exist."

Any assistance is appreciated,

OrrisJ
------------- CODE FRAGMENT BELOW ------------------------------------
IDataBufferPtrHandle Encrypt( IDataBufferPtrHandle pdbUnEncryptedData
)
{

***** Code Deleted ***************

///////////////////////////////////////////////////////
// Get the handle to the default key container within
// the default cryptographic service provider (CSP).
///////////////////////////////////////////////////////

if( !CryptAcquireContext( &m_hCryptProv, NULL, MS_ENHANCED_PROV,
PROV_RSA_FULL, 0 ) )
{
CErrorMsg( method, _T( "Error %x during CryptAcquireContext!\n" ),
GetLastError() );
CleanUp();
return NULL;
}

///////////////////////////////////////////////////////
// Encrypt using a random session key derived from
// the current users windows credentials. The ramdom
// session key and its size is saved along with the
// data.
///////////////////////////////////////////////////////

///////////////////////////////////////////////////////
// Create a random session key.

if( !CryptGenKey( m_hCryptProv, ENCRYPT_ALGORITHM, KEYLENGTH |
CRYPT_EXPORTABLE, &m_hKey ) )
{
CErrorMsg( method, _T( "Error %x during CryptGenKey.\n" ),
GetLastError() );
CleanUp();
return NULL;
}

///////////////////////////////////////////////////////
// Get the handle to the encrypter's exchange public
// key.

if( !CryptGetUserKey( m_hCryptProv, AT_KEYEXCHANGE, &m_hXchgKey ) )
{
CErrorMsg( method, _T( "Error %x User public key is not available
and may not exist.\n" ), GetLastError() );
CleanUp();
return NULL;
}

***** Code Deleted ***************
///////////////////////////////////////////////////////
// Export the session key into a simple key BLOB.

if( !CryptExportKey( m_hKey, m_hXchgKey, SIMPLEBLOB, 0, m_pbKeyBlob,
&dwKeyBlobLength ) )
{
CErrorMsg( method, _T( "Error %x during CryptExportKey!\n" ),
GetLastError() );
CleanUp();
return NULL;
}

***** Code Deleted ***************

///////////////////////////////////////////////////////
// Encrypt the data. After the successfull call to
// CryptEncrypt, dwDataLength will contain the length
// of the encrypted buffer.
///////////////////////////////////////////////////////

if( !CryptEncrypt( m_hKey, 0, TRUE, 0, m_pbBuffer, &dwDataLength,
dwBufferLength))
{
CErrorMsg( method, _T( "Error %x during CryptEncrypt!\n" ),
GetLastError() );
CleanUp();
return NULL;
}

///////////////////////////////////////////////////////
// Save key, key length, encrypted data and data length
// into the data buffer.

***** Code Deleted ***************

CleanUp();
return pIEncryptedData;
}
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"WilOJoe" <oj*****@filenet.com> wrote...
Does anyone have any ideas about why the Crypto API call to
CryptGetUserKey(.)would work just fine in WindowsXP but fails when
executed in Windows2000? [..][


Somebody in a newsgroup where it's on topic is likely able
to answer this. Try comp.os.ms-windows.programmer.win32

Victor
Jul 22 '05 #2

P: n/a
Thanks...I will try posting to comp.os.ms-windows.programmer.win32 as you suggest.

OrrisJ
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.