Re: How to decrypt a string?



Kevin Spencer <unclechutney@xxxxxxxxxxxx> wrote:
Not at all. The MemoryStream already contains a string. In essence, you are
converting a string to another string.

No. Encryption works on binary data, and it's not safe to treat
arbitrary binary data as if it were valid text data.

The OP is quite right to convert the encrypted bytes into a string
using Base64 and then convert the Base64 data back into bytes before
decryption.

What he's doing wrong is using StreamWriter.Write(bytes) instead of
just writing the converted data directly into the MemoryStream.

The encryption is:
Plaintext String -> Encrypted bytes -> Base64

The decrypion should thus be:
Base64 -> Encrypted bytes -> Plaintext String

Currently it's

Base64 -> Encrypted bytes -> ToString() -> Plaintext String

The call to ToString() is in the StreamWriter.Write(object) call.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: How to pass a vc++ BSTR value to C#.Net
    ... So we might have a suitation where an encryption might take place using COM ... Actually I'm able to return the binary data in the form of BSTR by using ... Encryption of a string doesn't give you another string. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: System.Text.Encoding help ????
    ... When converting arbitrary binary data like an encryption key or hash to/from ... When converting a string object to binary for encryption, etc., you need to ...
    (microsoft.public.dotnet.security)
  • Re: help..im stuck here
    ... converting it to binary first? ... The only advantage to converting your items ... If you're converting them to a String ... > May i know how to declare a string of binary data and pass it to the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: help..im stuck here
    ... oh..ya.i wan to pass it as a string....then separate them according to the ... The only advantage to converting your items ... If you're converting them to a String ... >> May i know how to declare a string of binary data and pass it to the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: extended chars and a web service
    ... which can be represented as a string but seem to give a validation error ... >> When I send encrypted character to this web service ... > Encryption usually results in binary data rather than string data, ... > you shouldn't be passing binary data as if it were string data. ...
    (microsoft.public.dotnet.framework.webservices)

Loading