EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Saving file after decryption

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#732
Posted: 07/17/2006 05:15:40
by Jim Bounce (Basic support level)
Joined: 07/11/2006
Posts: 13

Hi,

well sorry bothering you with my novice questions. Here´s my next problem. Decrypting file with a console app. with this:
Code
Try
                keyring.Load("D:\__tmp\pubring.pkr", "D:\__tmp\secring.skr", True)
                pgpReader.DecryptingKeys = keyring
                pgpReader.VerifyingKeys = keyring
                pgpReader.Passphrase = "Test"

                inF = New System.IO.FileStream(sourceFile, IO.FileMode.Open)
                outF = New System.IO.FileStream("D:\__tmp\autoencryption.eml", IO.FileMode.Create)
                Try
                    pgpReader.DecryptAndVerify(inF, 0)
                    outF = pgpReader.OutputStream()
                Catch ex As Exception
                    Console.WriteLine("unable to necrypt: " & ex.Message)
                    Console.ReadLine()
                End Try
                Console.WriteLine("Loaded successfull")
                Console.ReadLine()
            Catch ex As Exception
                Console.WriteLine("Failed to load keyring")
            End Try


my question is how to save the encrypted file to a filename specified in a code (or any other).

Thx a lot
regards
#733
Posted: 07/17/2006 05:39:42
by Eugene Mayevski (EldoS Corp.)

Please re-fomulate your question and define, what you want to save and where.


Sincerely yours
Eugene Mayevski
#734
Posted: 07/17/2006 05:45:37
by Jim Bounce (Basic support level)
Joined: 07/11/2006
Posts: 13

ok, well I define my file with:
sourceFile = "D:\__tmp\EMD-20060112-151000-0000029563.email.pgp"
proceeding with code pastet in a first post, so after calling this:
pgpReader.DecryptAndVerify(inF, 0)

I would like to save this decrypted file on thd harddrive.
In your example you are using a dialog to choose a filename, I will generate a name with a timestamp later on. I would like to save a file as D:\__tmp\autoencryption.eml

I hope it is possible to understand it now.

thx
#735
Posted: 07/17/2006 06:00:00
by Eugene Mayevski (EldoS Corp.)

You need to either set OutputStream property, or (what is more correct) handle OnCreateOutputStream event. You will find this all in the sample projects.


Sincerely yours
Eugene Mayevski
#736
Posted: 07/17/2006 06:56:26
by Jim Bounce (Basic support level)
Joined: 07/11/2006
Posts: 13

sorry for bithring you but I still can not solve this.
should I add this to my code:

Code
Private Sub pgpReader_OnCreateOutputStream(ByVal Sender As Object, ByVal Filename As String, ByVal TimeStamp As System.DateTime, ByRef Stream As System.IO.Stream, ByRef FreeOnExit As Boolean) Handles pgpReader.OnCreateOutputStream


How to set the OutputStream property.

thank you or your time
#740
Posted: 07/17/2006 10:00:50
by Jim Bounce (Basic support level)
Joined: 07/11/2006
Posts: 13

Even if I will risk a complete ban, here is once again a code of my sample application:
Code
Module Module1
    'SetLicenceKey()    
    Friend WithEvents pgpReader As SBPGP.TElPGPReader
    Public Sub Main()
        SBUtils.Unit.SetLicenseKey(SBUtils.Unit.BytesOfString("0375...B14D"))
        Dim pgpReader As New SBPGP.TElPGPReader
        Dim keyring As New SBPGPKeys.TElPGPKeyring
        Dim sourceFile As String
        Dim inF As System.IO.FileStream
        Dim outF As System.IO.FileStream
        sourceFile = "D:\__tmp\EMD-20060112-151000-0000029563.email.pgp"
        If System.IO.File.Exists(sourceFile) Then
            Try
                keyring.Load("D:\__tmp\pubring.pkr", "D:\__tmp\secring.skr", True)
                pgpReader.DecryptingKeys = keyring
                pgpReader.VerifyingKeys = keyring
                pgpReader.Passphrase = "das ist ein Test"

                inF = New System.IO.FileStream(sourceFile, IO.FileMode.Open)
                'outF = New System.IO.FileStream("D:\__tmp\autoencryption.eml", IO.FileMode.Create)
                Try
                    pgpReader.DecryptAndVerify(inF, 0)
                    outF = pgpReader.OutputStream()

                    'outF.Read(
                    'Dim info As Byte() = New Text.UTF8Encoding(True).GetBytes(outF.ReadByte)
                    'outF.Write(info, 0, info.Length)
                    'pgpReader_OnCreateOutputStream()
                Catch ex As Exception
                    Console.WriteLine("unable to necrypt: " & ex.Message)
                    Console.ReadLine()
                End Try
                Console.WriteLine("Loaded successfull")
                Console.ReadLine()
            Catch ex As Exception
                Console.WriteLine("Failed to load keyring")
            End Try
        Else
            Console.WriteLine("File to encrypt does not exists")
            Console.ReadLine()
        End If
        'pgpReader.DecryptingKeys()
    End Sub
    Private Sub pgpReader_OnCreateOutputStream(ByVal Sender As Object, ByVal Filename As String, ByVal TimeStamp As System.DateTime, ByRef Stream As System.IO.Stream, ByRef FreeOnExit As Boolean) Handles pgpReader.OnCreateOutputStream
        '  Handles pgpReader.OnCreateOutputStream
        ' The '_CONSOLE' filename should be handled in different way
        ' (for-your-eyes-only message), but we do not consider this case here.
        'saveFileDialog.FileName = Filename
        Stream = New System.IO.FileStream("D:\__tmp\autoencryption_yo.eml", IO.FileMode.Create)
        FreeOnExit = True
    End Sub
End Module


Event handler is never called, I tryed lot of things, but am not able to save the encrypted file on disk.

every advice would be usefull
#743
Posted: 07/17/2006 13:19:46
by Eugene Mayevski (EldoS Corp.)

Please do the search across the sample file for "OnCreateOutputStream". There's more than one entry, -- you missed assignment of the event handler.


Sincerely yours
Eugene Mayevski
#747
Posted: 07/18/2006 01:40:39
by Jim Bounce (Basic support level)
Joined: 07/11/2006
Posts: 13

Quote
Please do the search across the sample file for "OnCreateOutputStream". There's more than one entry, -- you missed assignment of the event handler.


Thats right it´s there twise in this line:

Code
Private Sub pgpReader_OnCreateOutputStream(ByVal Sender As Object, ByVal Filename As String, ByVal TimeStamp As System.DateTime, ByRef Stream As System.IO.Stream, ByRef FreeOnExit As Boolean) Handles pgpReader.OnCreateOutputStream


there´s nothing else. I am using the project PGPFilesDemo_VS005.

regards
#749
Posted: 07/18/2006 04:55:19
by Ken Ivanov (EldoS Corp.)

The pgpReader object is declared twice in your code:

1) Friend WithEvents pgpReader As SBPGP.TElPGPReader (module scope),

2) Dim pgpReader As New SBPGP.TElPGPReader (Main() function scope).

The OnCreateOutputStream handler of the inner pgpReader is not handled. Please consider removing the inner declaration and see if it solves the issue.
#754
Posted: 07/18/2006 06:08:16
by Jim Bounce (Basic support level)
Joined: 07/11/2006
Posts: 13

just trying once again with the advice from Ivanov,
thx a lot, gonna report it in few minutes

regards

CHANGE:
WOOORRRKKKSS!!! :))
thx a lot Ivanov.
now I am ready to purchase it.

regards
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

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