EldoS | Feel safer!

Software components for data protection, secure storage and transfer

PGP Encrypt, Sign, Decrypt and verify using C#

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.
Posted: 04/27/2015 07:10:25
by Vahagn Yeghikyan (Basic support level)
Joined: 04/27/2015
Posts: 4


sorry if this is a duplicate thread, but I could not find a satisfactory answer.

I created a certificate using opengpg Kleopatra and exported the public key to
public.asc file and secret key to "secret.gpg" file.

My code for encrypting a string looks as follows:

string _encryptAndSign(string s)
    //******* Creating the source stream **********
      MemoryStream SourceStream = new MemoryStream();      
      StreamWriter writer = new StreamWriter(SourceStream );
      stream.Position = 0;
   //******* End creating the source stream
     // ***** Encrypt and sign content **************

     MemoryStream output = new MemoryStream();

     using (TElPGPWriter twr = new TElPGPWriter())
                string publicKeyFile = System.Configuration.ConfigurationManager.AppSettings["publicKeyFile"];
                string secretKeyFile = System.Configuration.ConfigurationManager.AppSettings["secretKeyFile"];
                twr.EncryptingKeys = new SBPGPKeys.TElPGPKeyring();
                twr.EncryptingKeys.Load(publicKeyFile, secretKeyFile);
                twr.SigningKeys = new SBPGPKeys.TElPGPKeyring();
                twr.SigningKeys.Load(null, secretKeyFile);

                twr.Sign(stream, output);

                twr.EncryptAndSign(SourceStream , output);
                output.Position = 0;
     // ***** End Encrypt and sign content **************
       byte[] buffer = new byte[output.Length];
       output.Read(buffer, 0, (int)output.Length);
       return Convert.ToBase64String(buffer);


However, on line 'twr.EncryptAndSign' I get the following exception:

An exception of type 'SBPGPExceptions.EElPGPWriterException' occurred in SecureBlackbox.PGP.dll but was not handled in user code

Additional information: Signing failed (secret key mismatch/passphrase not provided?)

Could you please explain me what am I doing wrong and how to fix this?
Posted: 04/27/2015 07:19:34
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

You should implement TElPGPWriter.OnKeyPassphrase event handler an pass a password used to encrypt your private key there.

I’ve noticed there is no license ticket linked to your user account on EldoS site. Technical Support is provided to customers with the linked license tickets. You will find your license ticket together with all the details about how to use it in the registration e-mail that we’ve sent to you upon the purchase.

If you are evaluating the product and don't have a license yet, please let us know and then you can have support according to Basic support level. Basic support level includes answering basic technical questions that appear during product evaluation period.
Posted: 05/04/2015 04:03:16
by Vahagn Yeghikyan (Basic support level)
Joined: 04/27/2015
Posts: 4

Hi Vsevolod,

thanks for your quick response and sorry for my late reply.
Currently we are experimenting with your library. If it is fast and reliable enough we will buy it. Of course, first we have t get it work. Could you please answer one more question.

In my code I am writing:

using (TElPGPReader tr = new TElPGPReader())

                tr.DecryptingKeys = _keyRing;
                tr.VerifyingKeys = _keyRing;

                tr.KeyPassphrase = _passphrase;
                tr.OutputStream = new MemoryStream();
                using (var T = _getStreamFromByteArray(Content))
                    await tr.DecryptAndVerifyAsync(T, 0);
                    tr.OutputStream.Position = 0;

where _keyRing and _passphrase are some initialized local vars. The problem is that if I call DecryptAndVerify everything works well. However the async version hangs on that line indefinitely. Is there a workout?
Thanks in advance.
Posted: 05/04/2015 04:33:55
by Ken Ivanov (EldoS Corp.)

Hi Vahagn,

It's weird, as the only thing that DecryptAndVerifyAsync() does is creates an awaitable task and executes DecryptAndVerify() in it. Could you please specify the exact .NET framework version you are running the code on?

Posted: 05/04/2015 04:39:51
by Vahagn Yeghikyan (Basic support level)
Joined: 04/27/2015
Posts: 4

.Net 4.5. Visual Studio 2013.
Posted: 05/04/2015 05:05:13
by Vahagn Yeghikyan (Basic support level)
Joined: 04/27/2015
Posts: 4

Switched to .Net 4.5.1. The same issue.

Can the problem be related to the fact that we are using a trial version of the library?
Posted: 05/04/2015 05:39:33
by Ken Ivanov (EldoS Corp.)

I'm afraid we've been unable to reproduce the issue locally.

I suggest that we continue the discussion in the help desk, as we would need to send some test code to you (and the forum doesn't support binary attachments). The help desk is our online ticketing system, convenient and secure. I'm going to create a ticket for you; you will receive an e-mail confirmation once the ticket has been created.

The problem should not be related to the fact that you are using a trial version; it rather seems to be a local issue specific to the environment or to the way the SecureBlackbox assemblies are used.

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.



Topic viewed 1447 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!