EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TelPGPReader OutputStream is empty

Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.
#28563
Posted: 02/25/2014 15:10:27
by Lance Barger (Basic support level)
Joined: 02/25/2014
Posts: 4

Good afternoon I hope your day is going well.

My name is Lance and I work for CBRE, we are currently in the process of purchasing SBB in order to do PGP encryption. I am having difficulty decrypting pure text that I encrypted with TelPGPWriter. The encrypted stream looks fine and contains 426 bytes. When I decrypt however the reader's output stream always has length 0. I have tried using OnCreateOutputStream as well as setting the stream directly. Note that after calling DecryptAndVerify the reader's ProcessedLength shows 426, but the OutputStream is still empty. Any help is greatly appreciated.

Code

public MemoryStream PgpDecryptStream(MemoryStream cipherStream)
        {
            outputStream = new MemoryStream();

            var keyLoader = new TElPGPSecretKey();
            keyLoader.LoadFromFile("C:\\EncryptionKeys.txt");

            TElPGPKeyring EncKeyring = new TElPGPKeyring();
            EncKeyring.AddPublicKey(keyLoader.PublicKey);
            EncKeyring.AddSecretKey(keyLoader);

            var reader = SetupReader();

            reader.DecryptingKeys = EncKeyring;
            reader.VerifyingKeys = EncKeyring;
            reader.KeyPassphrase = "encryptorPassword";
            reader.OutputStream = outputStream;

            reader.DecryptAndVerify(cipherStream, 0);

            return (MemoryStream)reader.OutputStream;
        }

private TElPGPReader SetupReader()
        {
            var reader = new TElPGPReader();

            reader.DecryptingKeys = null;
            reader.KeyPassphrase = null;
            reader.OutputStream = null;
            reader.Passphrase = null;
            reader.VerifyingKeys = null;
            
            return reader;
        }
#28564
Posted: 02/25/2014 15:38:30
by Ken Ivanov (EldoS Corp.)

Hello Lance,

Thank you for contacting us.

The length of 426 is a bit too small for encrypted non-empty file, so I tend to believe that the protected file is indeed empty. Could you please re-check that the protection process goes/went correctly?

A good idea here is to use PGPFiles sample as an arbitrator - please try to encrypt the file with the sample and then decrypt it with your code. The outcome will help to tell whether the problem is specific to encryption or decryption stage.
#28565
Posted: 02/25/2014 15:54:07
by Lance Barger (Basic support level)
Joined: 02/25/2014
Posts: 4

Thank you for a quick response. I had suspected the same thing and indeed needed to verify that the protection process worked, as a result I added armoring to the protection and believe that the protected stream is correct, please see the stream, converted to string below.

Also, I have an implementation of this using FileStream instead of MemoryStream and it works fine in both directions and with the same keys. For the text only code all I did (originally) was replace 'FileStream' with 'MemoryStream' and the issue cropped up.

-----BEGIN PGP MESSAGE-----
Generator: EldoS SecureBlackbox. This is an EVALUATION version that will expire in 64 days.

wYwDZ6oEaHheYeQBA/0UimHuw7ex+nofVKSj2eDVm22OXG2hTGDk7W3ppZkY2UBs
H+MiWWnqUoQBjhj2IejhqbTwAd2XYmns9rTwLl62Tt29plQ7OCV5Nta1I+hJZShm
eDHusKNchynE4Apzqxtt2F9zjUYoEX5KVLgkOwKX4Fku5iePWBoJfWwYGDrLFNIz
AQo5wePLk6T1hB1TML6LiwmDsdzJhlxmYw6KnAlz3LzA+qVvQJd+msAwVP5zvh/i
oHnZ
=SWSS
-----END PGP MESSAGE-----
#28567
Posted: 02/25/2014 17:02:53
by Ken Ivanov (EldoS Corp.)

Lance,

A typical mistake when using the MemoryStream is forgetting to rewind the stream after writing source data to it. The components do not rewind input streams, so it is your responsibility to set the stream pointer to 0 after writing the data to be encrypted to the stream.
#28576
Posted: 02/26/2014 07:10:03
by Lance Barger (Basic support level)
Joined: 02/25/2014
Posts: 4

Indeed, I have made that mistake before :) but I had rewound the cipherStream prior to passing it to my decryption method. Just for completeness I rewound all streams prior to DecryptAndVerify so you could see, same result:

Code
public MemoryStream PgpDecryptStream(MemoryStream cipherStream)
        {
            outputStream = new MemoryStream();

            var keyLoader = new TElPGPSecretKey();
            keyLoader.LoadFromFile("C:\\EncryptionKeys.txt");

            TElPGPKeyring EncKeyring = new TElPGPKeyring();
            EncKeyring.AddPublicKey(keyLoader.PublicKey);
            EncKeyring.AddSecretKey(keyLoader);

            var reader = SetupReader();

            reader.DecryptingKeys = EncKeyring;
            reader.VerifyingKeys = EncKeyring;
            reader.KeyPassphrase = "encryptorPassword";
            reader.OutputStream = outputStream;

            cipherStream.Position = 0;
            outputStream.Position = 0;
            reader.OutputStream.Position = 0;

            reader.DecryptAndVerify(cipherStream, 0);

            return (MemoryStream)reader.OutputStream;
        }
#28577
Posted: 02/26/2014 07:38:23
by Eugene Mayevski (EldoS Corp.)

As you are running the test, can you please do the following:
1) use your test to encrypt a sample file with sample keys provided in <SecureBlackbox>\Extra\PGPKeys folder
2) if the issue is reproduced with those keys, post the test code (complete project), original file and encrypted file to HelpDesk ( https://www.eldos.com/helpdesk/ )

This will let us reproduce the issue locally. If you say that it's MemoryStream that causes troubles, we need to inspect deeper, what's going on there.


Sincerely yours
Eugene Mayevski
#28580
Posted: 02/26/2014 09:08:32
by Lance Barger (Basic support level)
Joined: 02/25/2014
Posts: 4

Okay that works thank you very much.

I guess I don't know enough about how to generate the keys. Could you forward some links or guidance on this?

Thanks in advance!

Lance
#28585
Posted: 02/26/2014 14:20:54
by Vsevolod Ievgiienko (EldoS Corp.)

Please refer to our sample that is located in \EldoS\SecureBlackbox.NET\Samples\C#\OpenPGPBlackbox\Desktop\PGPKeys folder.
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 1099 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!