EldoS | Feel safer!

Software components for data protection, secure storage and transfer

DecryptAndVerify => CreateOutputStream

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.
#1429
Posted: 10/11/2006 20:05:19
by Dan Hammari (Basic support level)
Joined: 06/27/2006
Posts: 11

Hello,

I am attempting to decrypt a PGP file and have the application automatically save the clear file to the same directory. The source example shows the OnCreateOutputStream calling a function with a save dialog to save the file. I'm having trouble altering the CreateOutputStream procedure so that it will automatically save to a directory. As I understand the OnCreateOutputStream event, it calls a procedure and automatically passes the Sender, Filename, TimeStamp, Stream, and FreeOnExit entities. The variable Stream comes in as null and the varaiable FreeOnExit comes in as False. I attempt to instantiate the Stream and set the FreeOnExit boolean to True, but I get the following error: "Abstract Error"

I must not be understanding how the OnCreateOutputStream event is supposed to populate the outputStream so I can automatically save the file without the need of the save dialog. Could someone point me in the right direction?

Notes: I am using SecureBlacbox in Delphi7.
Code Excerpts:

Code
  pgpDecryptKeyring.Load(myPublicKey,myPrivateKey);
  pgpDecryptReader.DecryptingKeys := pgpDecryptKeyring;
  pgpDecryptReader.VerifyingKeys := pgpDecryptKeyring;
  pgpDecryptReader.KeyPassphrase := privateKeyPassphrase;
  outputStream := TStream.Create;
  pgpDecryptReader.OutputStream := outputStream;
  pgpDecryptReader.DecryptAndVerify(inputStream,0);
...
...
...
procedure TfrmMain.pgpDecryptReaderCreateOutputStream(...)
  begin
    Stream := TStream.Create;
    FreeOnExit := True;
  end;


Thanks in advance for your help.
Sincerely,
-Dan
#1430
Posted: 10/12/2006 01:34:29
by Ken Ivanov (EldoS Corp.)

Quote
I must not be understanding how the OnCreateOutputStream event is supposed to populate the outputStream so I can automatically save the file without the need of the save dialog. Could someone point me in the right direction?

In order to save the decrypted data to file you should create the instance of TFileStream class and return it to the Stream parameter of the OnCreateOutputStream event:
Stream := TFileStream.Create('C:\myfile', fmCreate);
FreeOnExit := true
#1431
Posted: 10/12/2006 01:35:02
by Eugene Mayevski (EldoS Corp.)

1) TStream is an abstract class, which is useless.
2) use either OutputStream property of the event, but not both.


Sincerely yours
Eugene Mayevski
#1470
Posted: 10/19/2006 12:45:21
by Dan Hammari (Basic support level)
Joined: 06/27/2006
Posts: 11

Thanks for your help. I have bypassed the onCreateOutputStream event completely and simply referenced the outputStream variable. Here is the working code:

Code
pgpDecryptKeyring.Load(myPublicKey,myPrivateKey);
pgpDecryptReader.DecryptingKeys := pgpDecryptKeyring;
pgpDecryptReader.VerifyingKeys := pgpDecryptKeyring;
pgpDecryptReader.KeyPassphrase := privateKeyPassphrase;
outputStream := TFileStream.Create(decryptedFilePath,fmCreate);
pgpDecryptReader.OutputStream := outputStream;
pgpDecryptReader.DecryptAndVerify(inputStream,0);
inputStream.Free;
myPublicKey.Free;
myPrivateKey.Free;

// save the outputStream to a file
fileSize := outputStream.Size;
outputStream.Position := 0;
endOfFileStream := 1;
outputString := '';

// read the FileStream to a String
while endOfFileStream = 1 do
  begin
    endOfFileStream := outputStream.Read(currentCharacter,1);
    if endOfFileStream = 1 then
      outputString := outputString + Char(currentCharacter);
  end;
outputStream.Free;

// write the String to a file
AssignFile(clearFile,decryptedFilePath);
ReWrite(clearFile);
Write(clearFile,outputString);
CloseFile(clearFile);

Reply

Statistics

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