简体   繁体   中英

c++ decrypt file downloaded from server

I'm new to this, so please bear with me..

I'm using the following function to download files from a web server. This seems to work well without any major issues.

void downloadFile(const char* url, const char* fname) {
    CURL *curl;
    FILE *fp;
    CURLcode res;
    curl = curl_easy_init();
    if (curl){
        fp = fopen(fname, "wb");
        curl_easy_setopt(curl, CURLOPT_URL, url);
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        fclose(fp);
    }
}

downloadFile("http://servera.com/file.txt", "filename.txt");

Some of the files that are on the server have been encrypted (by me) using openssl using a command similar to:

openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.enc

These files download fine, but I'd like to have them download and be written to their locations decrypted all by the download function.

Is that possible ? If so can someone help me work out how. The password to decrypt the files will be saved in an array along with several other entries.

Any ideas ?

Thanks

Of course that's possible. The openssl command line tool just uses the libssl library internally to do the crypto.

You can do the same; I won't give an introduction to libssl here. I trust you can find the openssl homepage and read the relevant man pages yourself :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM