EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Decryption error after loading secret key

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#18259
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.
#18260
Posted: 11/21/2011 15:59:01
by Eugene Mayevski (EldoS Corp.)

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
#18271
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:
Code
   SecretKey.SaveToFile('C:/PgpTesting/Test.pgp');


Here is the loading:
Code
  
   SecretKey.LoadFromFile('C:/PgpTesting/Test.pgp');
   PgpKeyring.AddSecretKey(SecretKey);


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

   PgpRead.OutputFile := 'C:/PgpTesting/Output.xlsx';
   PgpRead.DecryptAndVerifyFile(FilePath.Text);
#18273
Posted: 11/22/2011 17:22:19
by Ken Ivanov (EldoS Corp.)

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?
#18274
Posted: 11/22/2011 17:37:14
by Albert Portillo (Standard support level)
Joined: 11/21/2011
Posts: 7

Code
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.
#18280
Posted: 11/23/2011 02:13:41
by Vsevolod Ievgiienko (EldoS Corp.)

Hello.

What about the call stack? Did you try to load your keys as Innokentiy suggested?
#18286
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?
#18287
Posted: 11/23/2011 17:20:28
by Ken Ivanov (EldoS Corp.)

The pieces of your code look correct. Let me remind you about the call stack, what is essential for pinpointing the issue.
#18315
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.
#18316
Posted: 11/28/2011 09:51:15
by Eugene Mayevski (EldoS Corp.)

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: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.

Reply

Statistics

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