Decryption using memory stream only?

210 views
Skip to first unread message

Phil Newell

unread,
Dec 6, 2011, 11:26:47 AM12/6/11
to DidiSoft Forum
I am interested in purchasing your software, but I have a very strict
requirement that no data be written to disk during the decryption
process, must be memory only. Could you please confirm that your
PGP .Net product will decrypt in memory with no data written to disk.

Regards Phil

didisoft

unread,
Dec 6, 2011, 11:54:16 AM12/6/11
to DidiSoft Forum
Hi Phil,

Yes we do support in memory decryption with no data written to the
disk (even temporary data).

An example can be found here:
http://www.didisoft.com/net-openpgp-library/decrypt-file/#DecryptStream

You can change the stream parameters to any other class that extends
System.IO.Stream.
The only thing that you have to be aware of is that the decrypted
content is written to a Stream
and for example if you want to read it lately you have to take an
extra step.

For your convenience I have included below a modified example that
decrypts to a MemoryStream, and afterwards a new MemoryStream instance
is created in order to have access to the decrypted data.
(I have used C#, please let me know if you prefer a VB.NET code
snippet)

using System;
using System.IO;
using DidiSoft.Pgp;

public class DecryptStreamDemo
{
public void Demo()
{
// initialize the library
PGPLib pgp = new PGPLib();

Stream privateKeyStream = null;
Stream inputFileStream = null;
Stream decryptedStream = null;

Stream decryptedStreamForReading = null;
try {
privateKeyStream = new FileStream(@"c:\private_key.asc",
FileMode.Open);
inputFileStream = new FileStream(@"c:\INPUT.pgp",
FileMode.Open);
string privateKeyPassword = "key password";
decryptedStream = new MemoryStream();

// decrypt and obtain the original file name
string originalFileName =
pgp.DecryptStream(inputFileStream,
privateKeyStream,
privateKeyPassword,
decryptedStream);


decryptedStreamForReading = new
MemoryStream(decryptedStream.ToArray());
// ... now you can read the decrypted data from
decryptedStreamForReading
} finally {
inputFileStream.Close();
privateKeyStream.Close();
decryptedStream.Close();
}
}
}

Please let me know if you need additional examples.

Kind Regards,
Peter Kalef
DidiSoft Ltd.

Reply all
Reply to author
Forward
0 new messages