473,405 Members | 2,445 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,405 software developers and data experts.

Going from Platform SDK CSP to .NET Cryptograhic Services

Hello,

I've spent the last two days learning and trying to write a c# class to
reflect what I already have in C++. The code below shows the method I use in
C++ (VS 6) to decrypt our encrypted values.

Expand|Select|Wrap|Line Numbers
  1. BOOL        bResult = TRUE;
  2. HCRYPTPROV    hProv = NULL;
  3. HCRYPTKEY    hKey = NULL;
  4. HCRYPTKEY    hXchgKey = NULL;
  5. HCRYPTHASH    hHash = NULL;
  6. DWORD        dwLength;
  7.  
  8. // Get handle to user default provider.
  9. if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL,
  10. CRYPT_VERIFYCONTEXT))
  11. {
  12. // Create hash object.
  13. if (CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
  14. {
  15. // Hash password string.
  16. dwLength = sizeof(TCHAR)*_tcslen(g_szEncryptionData);
  17. if (CryptHashData(hHash, (BYTE *)g_szEncryptionData, dwLength, 0))
  18. {
  19. // Create block cipher session key based on hash of the password.
  20. if (CryptDeriveKey(hProv, CALG_RC4, hHash, CRYPT_EXPORTABLE, &hKey))
  21. {
  22. // Get the encrypted value from the registry
  23. dwLength = 32*sizeof(TCHAR);
  24. DWORD dwType = REG_BINARY;
  25. if (RegQueryValueEx(m_hKey, lpszValueName, NULL, &dwType,
  26. (BYTE*)szValue, &dwLength)==ERROR_SUCCESS)
  27. {
  28. if (!CryptDecrypt(hKey, 0, TRUE, 0, (BYTE *)szValue, &dwLength))
  29. bResult = FALSE;
  30. }
  31. else
  32. {
  33. bResult = FALSE;
  34. }
  35. CryptDestroyKey(hKey);  // Release provider handle.
  36. }
  37. else                            {
  38. // Error during CryptDeriveKey!
  39. bResult = FALSE;
  40. }
  41. }
  42. else
  43. {
  44. // Error during CryptHashData!
  45. bResult = FALSE;                    }
  46. CryptDestroyHash(hHash); // Destroy session key.
  47. }
  48. else
  49. {
  50. // Error during CryptCreateHash!
  51. bResult = FALSE;
  52. }
  53. CryptReleaseContext(hProv, 0);
  54. }
  55.  
  56. return bResult;
  57.  
The new .NET stuff seems much more streamlined and fairly easier to use but
the documentation (or lack of) is making it very difficult for me to mirror
the info above. The key is to be able to write the same type of class the can
decrypt the info using a perdetermined key.

I would greatly appreciate it if anyone who has expertise in this area would
help me out here. Please don't hesitate to ask for more info from me.

Where I seem to be stuck is figuring out the parallel process for the
CryptDeriveKey method and how to tell it to use CALG_RC4. I think I have the
previous steps down, i.e., create an object and the md5 hash. Here's a c#
snippet:

Expand|Select|Wrap|Line Numbers
  1. byte[] md5Hash = new MD5CryptoServiceProvider().ComputeHash(keyHash);
  2.  
  3. CspParameters csp = new CspParameters();
  4. csp.Flags = CspProviderFlags.UseMachineKeyStore;
  5. csp.ProviderType = 1;    // PROV_RSA_FULL
  6.  
  7. RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(csp);
  8. byte[] btSignedData = rsa.SignData(keyHash, new MD5CryptoServiceProvider());
  9. byte[] btEncoded = rsa.Encrypt(btToEnc, false);
  10.  
  11.  
The code encodes fine but the encoded string does not match the C++ encoding
using the platform sdk cryptography.

Any ideas or help in resolving this would be greatly appreciated. I've
spent the last two days searching and searching and just can't find anything
to help in this area. I'm starting to glaze over. Thanks again.

May 2 '06 #1
0 1819

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

Similar topics

14
by: Pete Wood | last post by:
Hi All, Does anyone have any *unbiased* views (ie. hard facts) as to why .NET would be better than Java for the development of Enterprise applications? Best Regards, -- Pete Wood ..NET...
3
by: Keem | last post by:
Halo, Do anyone know that is COM+ is package together with Visual .NET Platform or it was an old technologies lastime? Thank you. Regards, Keem
4
by: Jonah Olsson | last post by:
Dear All, I'm currently developing a solution where large amounts of personalised emails are being created (and no, this is not spam...) on the ASP.NET platform and being delivered by a Debian...
0
by: Scupper | last post by:
I'm trying to write an application that will periodically check a server for certain services and, if they are not running, attempt to start them. I'm using System.ServiceProcess and have no...
13
by: Maxwell2006 | last post by:
Hi, We are having a debate over using DataSet as return value type for web services. The problem is that we don't know whether Java applications can use DataSet
44
by: herr | last post by:
Hi all, For some reasons, I am moving away from managed c# (after using it for 3 years) and want to code my windows application in native C++ (perfomance issues mainly). I already have a small...
3
by: Barrie Wilson | last post by:
I have a really simple test app which consumes two public web services (one stock quote and one Amazon books collection); it works just fine when posted on my local servers but when I publish it...
2
Niheel
by: Niheel | last post by:
Google launched a fully scalable web application platform today dubbed, Google App Engine. The platform allows developers to focus in on the application development and let Google handle the...
0
by: M.-A. Lemburg | last post by:
On 2008-05-01 13:37, Lance Gamet wrote: I don't think this is a Python question, but more a platform question. Users on different platforms will expect configuration data in different places....
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.