CJD
CJD

Reputation: 55

GPGME Decrypt showing No Data

I am writing a program where I encrypt a file and send it over an SSL Socket using gpgme. Then, I need to download the file and decrypt it.

My encryption is working fine, but I am having problems with the decryption. My inputBuffer is the contents of the file. When the file is downloaded, the result of the inputBuffer is the first line of the encrypted text. gpgme_strerror(err)) is returning "No Data". It doesn't seem as if the contents of the text is being placed in the cipher text and it doesn't know what to decrypt.

{
    bytes = SSL_read(ssl, &inputBuffer, 1024);

    while (bytes > 0)
    {
        err = gpgme_data_new_from_mem(&cipher, inputBuffer, strlen(inputBuffer), 0); 

        err = gpgme_op_decrypt(gctx, cipher, plain);
        fprintf(stderr,"The result from Decrypt: %s\n", gpgme_strerror(err)); // returning no data
        dec_result = gpgme_op_decrypt_result(gctx);
        if (dec_result->unsupported_algorithm)
        {
            fprintf(stderr, "%s:%i: unsupported algorithm: %s\n",
                         __FILE__, __LINE__, dec_result->unsupported_algorithm);
            exit(1);
        }

        fputs(inputBuffer, fp);
        fprintf(stderr, "Number of bytes read %zu\n", bytes);
        fclose(fp);
        fprintf(stderr, "File Uploaded Successfully\n");
        memset(&inputBuffer, '\0', sizeof(inputBuffer));
        bytes = SSL_read(ssl, &inputBuffer, 1024);
    }

    fclose(fp);
    SSL_shutdown(ssl);
}

Upvotes: 0

Views: 364

Answers (0)

Related Questions