473,396 Members | 1,671 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CryptGetUserKey works in WinXP but fails in Win2000

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
2 2880
"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
Thanks...I will try posting to comp.os.ms-windows.programmer.win32 as you suggest.

OrrisJ
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve | last post by:
My access 2000 project was written on a win 98 machine and has a macro with a condition DateValue(FileDateTime("c:\database\full22.txt"))<Date() This was written in expression builder. On...
2
by: MJC | last post by:
Hi All, I just built a database in Access XP/Win XP and am having an issue with the enter key behavior when the database is run under Windows 2000. If you use the enter key to tab through the...
2
by: Grei | last post by:
how can i impersonate from win2000 to WinXP? in MSDN says: (gives example how to implemet it but not with win2000, and it doesn't say what to do on win2000!!!) any ideas? workarounds? Thanx! ...
6
by: Grei | last post by:
how can i impersonate from win2000 to WinXP? MSDN gives example how to implemet impersonation from XP to XP, but not from win2000 to XP, and it doesn't say what to do with win2000!!! any ideas?...
0
by: Vincent Finn | last post by:
Hi, I am trying to use CreateProcessWithLogon in VB.net My code works fine when on a WinXP machine but fails on a Win2000 machine The error is "Object reference not set to an instance of...
4
by: Strahimir Antoljak | last post by:
I completed a VB.NET application and it runs fine on WinXP. I wanted to run it on Win2000 and it is not working. Is it not supposed to work on Win2000 too? (I installed .NET framework distributable...
10
by: JP Bless | last post by:
Hi all, I have a database Access/MSDE and would like to have a website so users can search the data and update some records/fields through the website.... And I have high speed internet...
1
by: thianseng | last post by:
Hi All, Urgent SOS!!! I developed my project using pyton 2.5 under winXP and had an issue in loading my dll if the target user is using Win2000. Initially, I thought it was caused by the dlls I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.