decompile page downloaded from server ?

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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



You'll need some way to identify the files you want to decompress. The conventional approach is to apply a unique extension. You can then kick off the decompress once the download has completed.

The decompress should be done using system() to run the openssl to do the decompress. I normally advise against using system(), but the openssl API is so bad, that it is a waste of time trying to use it. Further more, there's no guarantee that your code will work if openssl is upgraded. So just stay away from the openssl API, and just use the openssl program. It's the only reliable and portable way to use it.
Last edited on
Topic archived. No new replies allowed.