C++ Program two functions seal/open that encrypt/decrypt data using Hybrid Encryption.
Teslim sırasında ödenir
bool seal(const char * inFile, const char * outFile, const char * publicKeyFile, const char * symmetricCipher)
The function accepts four parameters, the first three parameters define the names of files. In the file inFile, you will find binary data intended for encryption, outFile is the output file where you save all the necessary data for decryption, and publicKeyFile is the public key that will be used to encrypt the symmetric key. The parameter symmetricCipher is the name of the symmetric cipher.
The function generates a symmetric (shared) key and an initialization vector (IV), which will be the input to the symmetric cipher symmetricCipher. You will encrypt the data in inFile with this cipher, key, and IV. Also, you encrypt the symmetric key with an asymmetric cipher (RSA) using the public key stored in publicKeyFile.
OpenSSL does most of the work for you:
PEM_read_PUBKEY reads the public key,
EVP_SealInit generates a shared key and IV (if necessary), encrypts the shared key, and sets the context,
EVP_SealUpdate and EVP_SealFinal work the same as in previous tasks.
Hybrid encryption is able to encrypt for multiple recipients. The data is encrypted only once with a shared key and IV, but the shared key can be encrypted with multiple public keys. Therefore, the function accepts an array of public keys.
Output file format:
The output file will have the following structure:
position in file length structure description
0 4 B int NID - A numerical identifier for an OpenSSL cipher. (used symmetric cipher)
4 4 B int EKlen - length of the encrypted key
8 EKlen B unsigned char array Encrypted key using RSA
8 + EKlen IVlen B unsigned char array Initialization vector (if needed)
8 + EKlen + IVlen --- unsigned char array Encrypted data
Expected function behavior:
Returns true in case of success, false otherwise.
In case the function returns false, the output file will not exist.
bool open(const char * inFile, const char * outFile, const char * privateKeyFile )
In the file inFile, you will find an encrypted file in the same format as the output file from the seal function. Write the decrypted data to the output file outFile - binary identity with the input file to the seal function is expected. This time, the private key for decrypting the encrypted key can be found in privateKeyFile. The functions PEM_read_PrivateKey, EVP_OpenInit, EVP_OpenUpdate, and EVP_OpenFinal will play a key role in this function.
Sample data contents
[login to view URL] - public key (try to open it as a txt file),
[login to view URL] - private key,
[login to view URL] - file with declarations and a basic test,
[login to view URL] - encrypted file. You can use it to test decryption. It was encrypted using the attached private key. After decryption, you will find ASCII text in it. If you encrypt the same data, the file will not be the same as [login to view URL] - a different key and IV were used.
There are many places in this task where functions may return an error. Check and consider automatically releasing resources using unique_ptr (applies to context, key, allocated arrays, and file closing).
The length of the encrypted key depends on the public key. You cannot count on a fixed length.
When compiling, do not forget to link the OpenSSL crypto library using -lcrypto.
The OpenSSL version on progtest is 1.1.1n.
All "notes" from the previous task apply.
Proje NO: #36522965
Bu iş için 5 freelancer ortalamada $37 teklif veriyor
Hello Client! I am a senior expert with 10+ years of strong experience in C/C++ Programming and Cryptography. If you hire me, I will perfectly complete two functions seal/open that encrypt/decrypt data using hybrid enc Daha Fazla
I am familiar with your topic. Kindly allow me to start working on it. I GUARANTEE you high quality, detailed, self-tailored paper to your specifications and within the stipulated time frame