Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Strings and streams

I have a bunch of strings that I want to encrypt before saving and decrypt on load, so they're never on disk in cleartext. Crypto API is stream-based.

So, how do I convert a string to a MemoryStream, and a MemoryStream to a string? Seems it should be really trivial, but if it is, then I've overlooked something.

Jon Shemitz
Tuesday, November 12, 2002

Check out the readers and writers. I'm far from an expert but this should work:


StreamWriter writer = new StreamWriter(yourmemorystream);
writer.Write(yourstring);
writer.Close();

mb
Tuesday, November 12, 2002

Thanks - I just didn't see that two step process of create a writer for the stream, then write the string to the writer.

That should be simpler than the System.Text Encoding code I'm using now ... and may even work.

Jon Shemitz
Tuesday, November 12, 2002

*  Recent Topics

*  Fog Creek Home