EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Can't sign file when PGP Encrypting

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#15009
Posted: 11/10/2010 17:22:36
by Warrick FitzGerald (Standard support level)
Joined: 03/12/2007
Posts: 14

Hi Guys,

I've read the docs and I've reviewed the code samples, but for the life of me I can't sign my files when I encrypt.

I keep getting the following error:
"Signing failed (secret key mismatch/passphrase not provided?)"

I've tried using
PGPWriter.Passphrases.Add("*****");

as well as the OnKeyPassphrase event, but neither seem to work for me.

I then tried using the sample application and that does work - so I know I'm usin the correct passphrase, however I must be missing something.

Can soomeone see anything wrong here?

// Define the public Key
SBPGPKeys.TElPGPKeyring PublicKey = new SBPGPKeys.TElPGPKeyring();
PublicKey.Load("", PublicRing, true);

// Instantiate the writer and set it's properties
TElPGPWriter PGPWriter = new TElPGPWriter();
PGPWriter.EncryptionType = TSBPGPEncryptionType.etPublicKey;
PGPWriter.EncryptingKeys = PublicKey;

if (PublicSignRing != "")
{
SBPGPKeys.TElPGPKeyring PublicSignKey = new SBPGPKeys.TElPGPKeyring();
PublicSignKey.Load("", PublicSignRing, true);

PGPWriter.SigningKeys = PublicSignKey;
}


// PGPWriter.OnKeyPassphrase += new SBPGPStreams.TSBPGPKeyPassphraseEvent(PGPWriter_OnKeyPassphrase);
PGPWriter.Passphrases.Add("************");

PGPWriter.Compress = true;
PGPWriter.Filename = zTrueSourceFileName;
PGPWriter.SymmetricKeyAlgorithm = 3;

FileStream destination = File.OpenWrite(zTrueDestinationFile);
FileStream source = File.OpenRead(zTrueSourceFile);


if (PublicSignRing != "")
{
PGPWriter.EncryptAndSign(source, destination, 0);

}
else
{
PGPWriter.Encrypt(source, destination, 0);
}
#15013
Posted: 11/11/2010 01:41:11
by Eugene Mayevski (EldoS Corp.)

If you check documentation, you will find that Passphrases is not a password for a key but a passphrase for password-based encryption. To set a password for a key you need to use either OnKeyPassphrase event or Passphrase property of ElPGPSecretKey object.

However your real problem is that your code doesn't load a secret key. You seem to be loading public keys only (I can't say for sure cause I don't know what exactly is contained in the file you are reading).

So in general you need to check the samples. We have several "primitive" samples which are easier to deal with. I suggest that you look into them.


Sincerely yours
Eugene Mayevski
#15019
Posted: 11/11/2010 09:45:52
by Warrick FitzGerald (Standard support level)
Joined: 03/12/2007
Posts: 14

Thanks for the quick response.

The "primitive" samples do seem a lot clearer, and I think I now understand what you mean that I was not loading any private keys. I'm not loading both the public and private into one ring and using that.

I re-wrote the sample in a straight forward method, doing what I think is now correct, but am still getting the same error. I'm sure there's something really silly I'm missing here, but I can't for the life of me figure out what.

[WebMethod]
public Encrypt_response EncryptTest(string keyID, string signKeyID, string sourceFile, string destinationFile)
{
string error = null;
Encrypt_response response = new Encrypt_response();

initBlackBox();

try
{

keyID = "endUser";
signKeyID = "PGPTest1";
sourceFile = @"\\10.100.200.54\FileStorage\TestFiles\Warrick\20080118_101708371.png";
destinationFile = @"\\5.5.5.5\FileStorage\TestFiles\Warrick\Out\test2.gpg";

String PublicKey = PGPKeysFolder + "\\public-" + keyID + ".txt";
String PrivateSignKey = PGPKeysFolder + "\\private-" + signKeyID + ".txt";

// Define the public Key
SBPGPKeys.TElPGPKeyring KeyRing = new SBPGPKeys.TElPGPKeyring();

// Instantiate the writer and set it's properties
TElPGPWriter PGPWriter = new TElPGPWriter();
PGPWriter.EncryptionType = TSBPGPEncryptionType.etPublicKey;

KeyRing.Load(PublicKey, PrivateSignKey, true);
PGPWriter.SigningKeys = KeyRing;


PGPWriter.OnKeyPassphrase += new SBPGPStreams.TSBPGPKeyPassphraseEvent(PGPWriter_OnKeyPassphrase);

PGPWriter.EncryptingKeys = KeyRing;
PGPWriter.Compress = true;
PGPWriter.Filename = sourceFile;
PGPWriter.SymmetricKeyAlgorithm = 3;

FileStream destination = File.OpenWrite(destinationFile);
FileStream source = File.OpenRead(sourceFile);

PGPWriter.EncryptAndSign(source, destination, 0);

source.Close();
destination.Close();

}
catch (Exception ex)
{
error = ex.Message;
response.Error = true;
response.Message = error;
}
return response;
}

void PGPWriter_OnKeyPassphrase(object Sender, SBPGPKeys.TElPGPCustomSecretKey Key, ref string Passphrase, ref bool Cancel)
{

Passphrase = "test1";
Key.Passphrase = "test1";

string logEntry = "Private key password supplied by server 4";
logger.log(LTFramework.guid + ".txt", "==Private Key Password==", logEntry);

Cancel = true;
}
#15023
Posted: 11/11/2010 17:07:51
by Warrick FitzGerald (Standard support level)
Joined: 03/12/2007
Posts: 14

ok, so I know I'm being annoying ... but .. I have a client that's really pushing for this .. any help would be greatly appreciate.

Thanks in advance
Warrick
#15026
Posted: 11/12/2010 01:51:14
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

Are these files keyrings? You should pass keyring files to KeyRing.Load(...); function.

Code
String PublicKey = PGPKeysFolder + "\\public-" + keyID + ".txt";
String PrivateSignKey = PGPKeysFolder + "\\private-" + signKeyID + ".txt";


Change your handler to

Code
void PGPWriter_OnKeyPassphrase(object Sender, SBPGPKeys.TElPGPCustomSecretKey Key, ref string Passphrase, ref bool Cancel)
{
   Passphrase = "test1";
            
   string logEntry = "Private key password supplied by server 4";
   logger.log(LTFramework.guid + ".txt", "==Private Key Password==", logEntry);
}
#15032
Posted: 11/12/2010 08:15:50
by Warrick FitzGerald (Standard support level)
Joined: 03/12/2007
Posts: 14

No, these file are the PGP certificates themself. I've attached one as an example.


[ Download ]
#15033
Posted: 11/12/2010 08:38:24
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

Have you tried to perform the same task with PGPFilesDemo, does it work for you?
Also, please check if KeyRing.SecretKeyCount is non-zero.
#15036
Posted: 11/12/2010 09:53:30
by Warrick FitzGerald (Standard support level)
Joined: 03/12/2007
Posts: 14

KeyRing.SecretKeyCount IS 0. Drat. I guess that would explain a lot.

The PGPFilesDemo only allows you to select a KeyRing. But using a GPG keyring does work. I guess what I need to do is load a key from file and then add that to a KeyRing and then use that.
#15037
Posted: 11/12/2010 10:03:19
by Mykola Olshevsky (Basic support level)
Joined: 07/07/2005
Posts: 450

ElPGPKeyring is able to load keys from armored files (like one you attached).
#15038
Posted: 11/12/2010 10:06:20
by Warrick FitzGerald (Standard support level)
Joined: 03/12/2007
Posts: 14

Ok, so I replaced my initial logic with this:

SBPGPKeys.TElPGPPublicKey zPublicKey = new SBPGPKeys.TElPGPPublicKey();
SBPGPKeys.TElPGPSecretKey zSecretKey = new SBPGPKeys.TElPGPSecretKey();

zPublicKey.LoadFromFile(PublicKey);
zSecretKey.LoadFromFile(PrivateSignKey);

...
//KeyRing.Load(PublicKey, PrivateSignKey, true);
KeyRing.AddPublicKey(zPublicKey);
KeyRing.AddSecretKey(zSecretKey);

PGPWriter.SigningKeys = KeyRing;


The SecretKeyCount is now 1 - which is a good thing, but it's still raising the same exception.

Still seems to
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

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