I want to encrypt and decript small snippets of data. The data will be stored locally in a cookie, and remotely, in the database, in encrypted form. So, after the data value is encrypted in ASP.NET, how can I get the encrypted version so it can be passed to a stored procedure as a string value that gets written to a table in the database?
Using the .NET Rijndael encryption approach described here is it possible, immediately after writing the plain text value to the CryptoStream, to fetch its encrypted form? So that instead of writing "The message was sent" to the console, one would write the encrypted form of the value?
If so, how do we read the encrypted value from the CryptoStream after the encryption is complete?
Also, does this have to be done with a NetStream? Is there another kind of stream that doesn't require a TCP client?
Dim CryptStream As New CryptoStream(NetStream, RMCrypto.CreateEncryptor(Key, IV), CryptoStreamMode.Write)
'Create a StreamWriter for easy writing to the
'network stream.
Dim SWriter As New StreamWriter(CryptStream)
'Write to the stream.
SWriter.WriteLine("Hello World!")
'Inform the user that the message was written
'to the stream.
Console.WriteLine("The message was sent.")
The simplest way of doing this would be just to use a MemoryStream
MemoryStream
MemoryStream.ToArray
to get the encrypted dataNetStream
in this case, whatever that is)See more on this question at Stackoverflow