'Using Windows API in C++ to decrypt a file encrypted with openssl command line
I have to decrypt a file using Windows API (Cryptography or CNG) in C++ on Windows Embedded Compact 2013.
The file was encrypted by the following shell script using openssl command line:
_log "generate random password file"
openssl rand -out "${filename_password_txt}" -hex 64
_log "encrypt file using generated random password file"
_log " filename_to_encrypt = ${filename_to_encrypt}"
_log " filename_encrypted = ${filename_encrypted}"
_log " password.txt = ${filename_password_txt}"
openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -salt -in "${filename_to_encrypt}" -out "${filename_encrypted}" -pass file:"${filename_password_txt}"
_log "encrypt password file using the public key"
openssl rsautl -encrypt -inkey "${filename_public_key}" -pubin -in "${filename_password_txt}" -out "${filename_password_enc}"
In my windows code i have the private key, the encrypted password and the encrypted data file.
So i have to translate following openssl commands to Windows API:
_log "decrypt encrypted password file using the private key"
openssl rsautl -decrypt -inkey "${filename_private_key}" -in "${filename_password_encrypted}" -out "${filename_password_decrypted}"
_log "decrypt data file using the decrypted password"
openssl enc -d -aes-256-cbc -pbkdf2 -iter 100000 -in "${filename_datafile_encrypted}" -out "${filename_datafile_decrypted}" -pass file:"${filename_password_decrypted}"
I'm a bit lost because i haven't used the cryptography functions of Windows before. Did anyone have done something similar before and can share some ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
