473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Replace ASCII (null) value in string (RijndaelManaged)

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
5 9366
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Nicolas Bouillon | last post by:
Hi I would like to replace accentuel chars (like "é", "è" or "à") with non accetued ones ("é" -> "e", "è" -> "e", "à" -> "a"). I have tried string.replace method, but it seems dislike...
5
by: sathyashrayan | last post by:
Group, I have some doubts in the following program. ------------------program--------------------- /* ** Make an ascii binary string into an integer. */ #include <string.h> unsigned int...
4
by: Locusta | last post by:
Hello, I have been struggeling for replacing a string in a string. The snippet from the program below replaces the <, & and > with the XML equivalent values. In the program, I allocate space...
4
by: Derek Martin | last post by:
I have an object with several string elements that I would like to check for invalid characters in the properties of each element. Can I use string.replace to do that or is there a better...
3
by: Niyazi | last post by:
Hi all, I have a dataTable that contains nearly 38400 rows. In the dataTable consist of 3 column. column 1 Name: MUHNO column 2 Name: HESNO Column 3 Name: BALANCE Let me give you some...
5
by: int main(void) | last post by:
Hi all, Following is my attempt to write a string search and replace function. #include <stdio.h> #include <stdlib.h> #include <string.h>...
2
by: John Nagle | last post by:
I'm trying to clean up a bad ASCII string, one read from a web page that is supposedly in the ASCII character set but has some characters above 127. And I get this: File...
10
by: Samuel Karl Peterson | last post by:
Greetings Pythonistas. I have recently discovered a strange anomoly with string.replace. It seemingly, randomly does not deal with characters of ordinal value 127. I ran into this problem while...
18
by: Umesh | last post by:
Do you have any answer to it? thx.
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.