Why am I getting this exception: 'Invalid base stream specified. The stream is empty and its not writeable or seekable'?

+1 vote
asked Mar 8, 2018 by richzhen (130 points)
edited Mar 8, 2018 by richzhen

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


commented Mar 8, 2018 by richzhen (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)

Please log in or register to answer this question.

...