Click here to Skip to main content
15,791,520 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to develop an Envelop encryption program using C++ to symmetrically encrypt a plain text file using AES key and then assymetrically encrypt the AES key using a public RSA key.

Please suggest a suitable solution for this.

What I have tried:

I have tried using <wincrypt.h> api, but there is some problem, most probably because of the steps used.

I get a Parameter incorrect Error code 87 for CryptEncrypt. I have the following doubts in addition
1. Does the Plain text needs to be in hashed format ?
2. Is a session key required ?
Updated 25-Jun-19 0:22am
KarstenK 25-Jun-19 6:28am    
Hash is a form of a checksum and doenst encrypt anything. You really need to learn the basics befor solving that task.

I guess you are a bit lazy student now sitting on an assigment. :-O

I'm pretty sure that you don't understand what encryption is, and it would be a good idea if you found out before you started "playing" with code.
1. Does the Plain text needs to be in hashed format ?
No. If you do, you will destroy the data in the plain text file and will be unable to recover it. See here: Decrypting MD5 and SHA: Why You Can't Do It[^]
2. Is a session key required ?
No. If you use a session based key, the data you encrypt will only be decryptable while the session is still current - when the session ends, the session key will be discarded and the encrypted data will no longer be recoverable. Keys are fundamental to all (non-trivial) encryption algorithms and are needed for both encryption and decryption.

In addition, we can't possible diagnose your problems from a vague description like "Parameter incorrect Error code 87 for CryptEncrypt" because we have no idea what your code looks like!

What I would suggest is that you start off by learning what encryption is, and how to implement it properly - because this is a very complicated subject and if you make mistakes, then either your encryption will mean your data is not recoverable (this is bad) or your data is not safe (this is worse). It is far, far to easy to mess this up if you do not know what you are doing (and depending on what you are doing with it, leave yourself wide open to prosecution and massive fines for infringing GDPR).

I'd start reading here if I was you: learning what encryption is, and how to implement it properly - Google Search[^]
Share this answer
megaadam 25-Jun-19 4:23am    
What can possibly go wrong as long as you use <wincrypt.h> to encrypt the ICBM launch codez?
OriginalGriff 25-Jun-19 4:36am    
As long as it's only the nuclear codez no problem at all. My bank account password? Now we have a problem ... :laugh:
OriginalGriff 26-Jun-19 2:56am    
"This call fails and when I debug out the error code, it returns Error 87: Incorrect parameter."
That's not debugging it - that's "oh, it failed with an error message" followed by "I give up".
You have a debugger. Use it to look at the data and possible parameters and work out which one, then start looking for why.

I'm not wading through a pile of poor student grade code you found on the internet to work out what is wrong with it, especially when I can't run it under the same conditions you are!
Member 14511380 26-Jun-19 5:14am    
If you have Expert grade code for the same problem discussed above, please share the same, if permitted that is., while I continue to debug the issue.
Take a look at Cryptography API: Next Generation - Windows applications | Microsoft Docs[^]. It requires some reading but is fairly straightforward to use.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900