By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,955 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,955 IT Pros & Developers. It's quick & easy.

Replace ASCII (null) value in string (RijndaelManaged)

P: n/a
Hi

I am using the RijndaelManaged encryption method in C#, but when I
decode my string, the byte array is returning several ASCII null values
at the end of my string, which is represented by "\0".

What I would like to know, is how can I get rid of these null values as
obviously I don't want or need them.

Many thanks

Darren

// Code snippet
return Encoding.ASCII.GetString(bytTmp);

Aug 2 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
daz_oldham wrote:
Hi

I am using the RijndaelManaged encryption method in C#, but when I
decode my string, the byte array is returning several ASCII null values
at the end of my string, which is represented by "\0".

What I would like to know, is how can I get rid of these null values as
obviously I don't want or need them.

Many thanks

Darren

// Code snippet
return Encoding.ASCII.GetString(bytTmp);
try to use base64 encoding on the array to retrieve a ascii string.
Aug 2 '06 #2

P: n/a
daz_oldham <Da**************@gmail.comwrote:
I am using the RijndaelManaged encryption method in C#, but when I
decode my string, the byte array is returning several ASCII null values
at the end of my string, which is represented by "\0".

What I would like to know, is how can I get rid of these null values as
obviously I don't want or need them.
You're treating arbitrary binary data as if it were text - it's not.
Use Convert.ToBase64String instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 2 '06 #3

P: n/a
Hi Jon, Cody

When I try to do this, I am getting the following back ( my string =
"9").

"QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

The encryption clearly uses ASCII encoding, would I be better using
Unicode?

Many thanks

Darren

Jon wrote:
daz_oldham <Da**************@gmail.comwrote:
I am using the RijndaelManaged encryption method in C#, but when I
decode my string, the byte array is returning several ASCII null values
at the end of my string, which is represented by "\0".

What I would like to know, is how can I get rid of these null values as
obviously I don't want or need them.

You're treating arbitrary binary data as if it were text - it's not.
Use Convert.ToBase64String instead.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 3 '06 #4

P: n/a
daz_oldham wrote:
When I try to do this, I am getting the following back ( my string =
"9").

"QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
Yup - that's fairly reasonable.
The encryption clearly uses ASCII encoding, would I be better using
Unicode?
No. Encryption doesn't use ASCII encoding - it converts arbitrary
binary data to arbitrary binary data. Base64 is a safe way of
representing arbitrary binary data as text.

Jon

Aug 3 '06 #5

P: n/a
Ah, thanks Jon.

I did a search on RijndaelManaged c# and found loads of implementations
of this, and used another implementation of it - it has done the trick
so I am happy.

Thanks for your help.

Darren

Jon Skeet [C# MVP] wrote:
daz_oldham wrote:
When I try to do this, I am getting the following back ( my string =
"9").

"QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"

Yup - that's fairly reasonable.
The encryption clearly uses ASCII encoding, would I be better using
Unicode?

No. Encryption doesn't use ASCII encoding - it converts arbitrary
binary data to arbitrary binary data. Base64 is a safe way of
representing arbitrary binary data as text.

Jon
Aug 4 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.