+1 vote
by (130 points)
edited by

This is my first time using the Rebex Security module to encrypt and decrypt streams.

In my code, I am passing in to the Decrypt() method two streams. The sourceStream paramenter is of type StreamReader and the targetStream is a MemoryStream. The intention for the MemoryStream is to NOT write the Plain Text after decrypting back to the file system.

I am getting this exception at run-time; 'Invalid base stream specified. The stream is empty and its not writeable or seekable'.


StreamReader sourceStream = new StreamReader("CypherText.fil");
sourceStream.ReadToEnd();

MemoryStream targetStream = new MemoryStream();

FileEncryption fe = new FileEncryption();
fe.SetPassword("secret password");
fe.Decrypt(sourceStream.BaseStream, targetStream); <--exception here


1 Answer

0 votes
by (130 points)
Fixed it!  I've change the StreamReader to a FileStream object and the code executes to decrypt the Cypher Text now.  Of cause, the StreamReader's base class is a TextReader, not a Stream.

FileStream sourceStream = new FileStream(CypherText.fil, FileMode.Open, FileAccess.Read)
...