G
Gasnic
Hi,
I was doing a proof of concept on encryption and decryption. I tried to use the triple DES algorithm with the CryptoStream to encrypt the data.
I pass a literal string into the CryptoStream to encrypt the data into a MemoryStream. And then decrypt the MemoryStream back. But I am getting CryptographicException with Bad Data.
When I tried to encryption the same data into a FileStream and then decrypt the file, it works.
In short, it works when I use FileStream but not MemoryStream.
Another info I found is that the encrypted file is 16 bytes, and if I encrypt it to MemoryStream, the stream is in length 8.
I used StreamWriter to write data into the CryptoStream but I didn't specify the encoding.
Should I specify an encoding? if so, which encoding should I use?
Thanks first.
I was doing a proof of concept on encryption and decryption. I tried to use the triple DES algorithm with the CryptoStream to encrypt the data.
I pass a literal string into the CryptoStream to encrypt the data into a MemoryStream. And then decrypt the MemoryStream back. But I am getting CryptographicException with Bad Data.
When I tried to encryption the same data into a FileStream and then decrypt the file, it works.
In short, it works when I use FileStream but not MemoryStream.
Another info I found is that the encrypted file is 16 bytes, and if I encrypt it to MemoryStream, the stream is in length 8.
I used StreamWriter to write data into the CryptoStream but I didn't specify the encoding.
Should I specify an encoding? if so, which encoding should I use?
Thanks first.