EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Decryption error after loading secret key

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
Posted: 11/21/2011 15:29:16
by Albert Portillo (Standard support level)
Joined: 11/21/2011
Posts: 7

I'm trying to be able to load keys and decrypt files using them. The program I have built currently has no problem encrypting and decrypting files when the key was generated and used in that same session. However when I save the generated file then load the file in a different session and try to decrypt with it, it gives me an access violation error at a specified address. I would assume that the SecretKey.SaveToFile(Filename) and SecretKey.LoadToFile(Filename) would return the same key yet the decryption fails when I do the load. It only works if I generate then decrypt in the same session without doing any saving or loading. Am I missing something that has to be saved or loaded with the secret key? I am programming in Delphi. Any help would be appreciated.
Posted: 11/21/2011 15:59:01
by Eugene Mayevski (Team)

1) please try loading and saving your keys with PGPKeysDemo and see if it works for you.
2) show your code where you save and load the key (remember to use code button to mark the code when pasting it to the editor on this page).

Sincerely yours
Eugene Mayevski
Posted: 11/22/2011 16:04:02
by Albert Portillo (Standard support level)
Joined: 11/21/2011
Posts: 7

Here is the save to file line:

Here is the loading:

And here is the decrypting:
   PgpRead.DecryptingKeys := PgpKeyring;

   PgpRead.OutputFile := 'C:/PgpTesting/Output.xlsx';
Posted: 11/22/2011 17:22:19
by Ken Ivanov (Team)

Thanks. First of all, please use TElPGPKeyring.Load() method to load PGP keys (it's a kind of "good practice" advice). You can pass an empty string as a second parameter if you only need to load a secret OR public key.

Next, could you please also
1) show us the code you use to generate a keypair?
2) catch the call stack of the AV exception you get?
Posted: 11/22/2011 17:37:14
by Albert Portillo (Standard support level)
Joined: 11/21/2011
Posts: 7

SecretKey := TElPGPSecretKey.Create;        
SecretKey.Generate('password', 1024,SB_PGP_ALGORITHM_PK_RSA,1024,SB_PGP_ALGORITHM_PK_RSA,'user',0);

That is how I am generating the key.
Posted: 11/23/2011 02:13:41
by Vsevolod Ievgiienko (Team)


What about the call stack? Did you try to load your keys as Innokentiy suggested?
Posted: 11/23/2011 11:52:42
by Albert Portillo (Standard support level)
Joined: 11/21/2011
Posts: 7

Apparently it's not loading the key properly. Or maybe saving it for that matter.
I did the load as was suggested and am still receiving the same problem. Am I saving the key incorrectly?
Posted: 11/23/2011 17:20:28
by Ken Ivanov (Team)

The pieces of your code look correct. Let me remind you about the call stack, what is essential for pinpointing the issue.
Posted: 11/28/2011 09:11:13
by Albert Portillo (Standard support level)
Joined: 11/21/2011
Posts: 7

I'm not quite sure how to go about capturing the call stack. I did a try except and logged the exception message and I get the following: "No appropriate OpenPGP secret key for decryption found". Is this what I'm supposed to be getting? Sorry but I am fairly new to delphi.
Posted: 11/28/2011 09:51:15
by Eugene Mayevski (Team)

Call Stack is captured by opening Call Stack debug window (see main menu), then selecting all items and pressing Ctrl-C (or Ctrl-Ins, I don't remember for sure).
Put a breakpoint in except handler, and when the exception happens in IDE, capture the call stack.

Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.



Topic viewed 3950 times

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


Back to top

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

Got it!