EldoS | Feel safer!

Software components for data protection, secure storage and transfer

OpenPGP decryption using different keys

Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages
#23378
Posted: 02/08/2013 09:40:35
by Howard Adamson (Standard support level)
Joined: 02/08/2013
Posts: 2

I am using SecureBlackBox OpenPGP TElPGPReader.DecryptAndVerifyFile method to decrypt successfully PGP files using Delphi 2009. The users process several PGP files in a dir, get asked for the Key passphrase for the first file (this is stored) and used to successfully decypt all the other files. The problem happens if the PGP files have used different key passphrases, the key passphrase stored is now wrong and there is an error returned. I don't want a user to have to enter a key passphrase for every file decryption but to ask the user for key passphrase if the stored one is not correct?

procedure TCPDownloadForm.pgpReaderKeyPassphrase(Sender: TObject;
Key: TElPGPCustomSecretKey; var Passphrase: string; var Cancel: Boolean);
begin
Passphrase := RequestKeyPassphrase(Key, Cancel);
{Once KeyPassphrase entered, store for rest of downloads to process}
pgpReader.KeyPassphrase := Passphrase;
end;

Thanks
#23379
Posted: 02/08/2013 09:46:51
by Eugene Mayevski (EldoS Corp.)

The decryptor calls your event handler code in a loop until it gets the correct password or until you set Cancel to true. So you can cache many passwords and try them all. If none work, then ask the user.


Sincerely yours
Eugene Mayevski
#23382
Posted: 02/08/2013 10:05:48
by Howard Adamson (Standard support level)
Joined: 02/08/2013
Posts: 2

Hi,

Thank you for your quick reply. Do you have any example Delphi code showing this. I am not sure what delphi code changes and where I need to get this working?

I currently call:

{--------------------------------------------------------}
pgpReader.DecryptAndVerifyFile(strSourceFilepath + strSourceFilename);

{--------------------------------------------------------}

which then calls (if no pgpReader.KeyPassphrase specified):

{--------------------------------------------------------}
procedure TCPDownloadForm.pgpReaderKeyPassphrase(Sender: TObject;
Key: TElPGPCustomSecretKey; var Passphrase: string; var Cancel: Boolean);
begin
Passphrase := RequestKeyPassphrase(Key, Cancel);
{Once KeyPassphrase entered, store for rest of downloads to process}
pgpReader.KeyPassphrase := Passphrase;
end;

{--------------------------------------------------------}
function TCPDownloadForm.RequestKeyPassphrase(Key: TElPGPCustomSecretKey; var Cancel: Boolean): string;
var
UserName: string;
{$ifdef BUILDER_USED}
KeyID : TSBKeyID;
{$endif}
begin
Cancel := False;
Result := '';
with TfrmPGPPassphraseRequest.Create(Self) do
try
if (key <> nil) then
begin
if (key is SBPGPKeys.TElPGPSecretKey) then
begin
if (SBPGPKeys.TElPGPSecretKey(key).PublicKey.UserIDCount > 0) then
UserName := SBPGPKeys.TElPGPSecretKey(key).PublicKey.UserIDs[0].Name
else
UserName := '<no name>';
end
else
UserName := 'Subkey';

lbPrompt.Caption := 'Passphrase is needed for secret key:';
{$ifdef BUILDER_USED}
Key.GetKeyID(KeyID);
{$endif}
lbKeyID.Caption := UserName + ' (ID=0x' + KeyID2Str({$ifdef BUILDER_USED}KeyID{$else}key.KeyID(){$endif}, true) + ')';
end
else
begin
lbPrompt.Caption := 'Passphrase is needed to decrypt the message';
lbKeyID.Caption := '';
end;

if ShowModal = mrOK then
Result := edPassphrase.Text
else
Cancel := True;
finally
Free;
end;
end;
#23383
Posted: 02/08/2013 10:09:52
by Eugene Mayevski (EldoS Corp.)

We don't have a sample code, sorry.


Sincerely yours
Eugene Mayevski

Reply

Statistics

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