
Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
>>If you genuinely have text data
I have a string (well a bunch of them) that I need to encrypt (the result
being another string) and then store as part of an XML doc... At future
point, the encoded string from XML file must give me back the original
string (by decrypting)...
So encrypting:
string -> Encoding.Default.GetBytes() -> byteArray which encrypted returns
new byteArray -> ToBase64 ->encryptedString...
Decrypting:
encryptedString -> FromBase64 -> byteArray which decrypted returns new
byteArray ->Encoding.Default.GetString ->originalString...
So I'll take your suggestion and substitue use of Encoding.Default with
Encoding.UTF8...
Cheers
Daniel
Daniel Moth <dmoth74@hotmail.com> wrote:
> Regarding encrypting data I have found 3 implementations:
> 1. The msdn signature sample
[quoted text clipped - 6 lines]
> vice versa. I find that does not work if the string contains characters such
> as "?" (French e with accent). Instead the characters show as question
marks
> in a textbox after conversion. Of course, switching to Encoding.Default
> solves the problem.
>
> I cannot believe they all made the oversight so I presume I am missing
> something. Can anybody point me in the right direction or confirm that using
> Encoding.Default makes sense?
Encoding.Default isn't a good idea either, as a change to the locale
would invalidate everything. In fact, using any straight encoding with
encrypted data (which is usually binary) is a bad idea - I'd suggest
Base64 encoding the data instead. If you genuniely have text data, I'd
usually recommend UTF8 as a good encoding to use - it's universally
available, and compact for ASCII values.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon Skeet [C# MVP] - 03 Mar 2004 08:39 GMT
> >>If you genuinely have text data
>
[quoted text clipped - 13 lines]
> So I'll take your suggestion and substitue use of Encoding.Default with
> Encoding.UTF8...
Yup, that's a good idea. Apart from that though, it seems fine. The
main thing is not to try to go from the encrypted byte array to a
string just by using an encoding, which some people do :(

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Daniel Moth - 03 Mar 2004 15:35 GMT
Thanks again Jon...
What is worst than some people using an encoding in the end, is people
putting out samples that the rest of us follow with the said flows in them
:-(
Cheers
Daniel
> > >>If you genuinely have text data
> >
[quoted text clipped - 17 lines]
> main thing is not to try to go from the encrypted byte array to a
> string just by using an encoding, which some people do :(