Decrypted Output Stream Limited to 1024 Size

34 views
Skip to first unread message

Segun Abiodun

unread,
Dec 30, 2015, 6:17:29 PM12/30/15
to DidiSoft Forum
I am trying to decrypt a large file, but when I pass:

pgp.DecryptStream(response_stream, key_stream, password, response_output_stream);

The response_output_stream is always truncated to size 1024.

Please what could be the cause of this? I am using the Trial version of the PGPLibrary for .NET.

Would appreciate any help. Thanks.

didisoft

unread,
Jan 1, 2016, 3:56:02 PM1/1/16
to DidiSoft Forum
Hi Segun,

I've made a simple command line example that successfully decrypts a 20KB encrypted data using streams.
The example code (C#) is below. You can try it on your side:

----------
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Net;

using DidiSoft.Pgp;

namespace EncryptStream1024
{
    class Program
    {
        static void Main(string[] args)
        {
            //
            // You can change these to reflect yours
            //
            string pgpPublicKeyLocation = @"c:\Projects\PGPKeys\public.key";
            string pgpPrivateKeyLocation = @"c:\Projects\PGPKeys\private.key";
            string privateKeypassword = "changeit";

            // download some big text file (20KB in our case)
            var cli = new WebClient();

            // pgp encrypt 
            PGPLib pgp = new PGPLib();
            string encryptedText = pgp.EncryptString(data, pgpPublicKeyLocation);

            //
            // pgp decryption
            //
            MemoryStream outStream = new MemoryStream();
            using (Stream encryptedStream = new MemoryStream(UTF8Encoding.UTF8.GetBytes(encryptedText)))
            using (Stream keyStream = File.OpenRead(pgpPrivateKeyLocation)) 
            {                
                pgp.DecryptStream(encryptedStream, keyStream, privateKeypassword, outStream);
            }

            // do we have more than 1024 bytes ?!?
            Console.WriteLine(outStream.Length);
            Console.WriteLine("Press <ENTER> to exit.");
            Console.ReadLine();
        }
    }
}
-------

Please let me know of the outcome.

Best Regards,
Peter Kalef
DidiSoft Tech support

Segun Abiodun

unread,
Jul 20, 2016, 4:41:31 PM7/20/16
to DidiSoft Forum
Hello Peter,

Apologies for the so so late response to your post, I got a way around the problem the first time, but when it came back again in another implementation, I had to start searching all over again, until I ran into your response.

I have tested the DecryptStream method independently and it returned a whole lot more the 1024 bytes. Now I am narrowing the problem down to the web service in which I am calling the method. I will keep you posted on my findings.

Thanks again.

Best Regards,
Segun Abiodun
Reply all
Reply to author
Forward
0 new messages