473,406 Members | 2,549 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,406 software developers and data experts.

Problem with string type, is it a bug? known? .NET 1.1

Hi,
I encrypted a string using the RijndaelManaged class.

When decrypted, it happens that the string is longer then the original, but
the exceeding chars are nothing (string.chars(indexOfExceedingChars) is
nothing)

To correct the problem, I used SomeOtherStringVar = trim(DecryptedString)

The problem is the following: Trim(DecryptedString) returns the string
without the exceeding chars, but SomeOtherStringVar still contains them
after the assignation. Should they not be removed?!?

I dont understand, can someone enlight me please?

Thanks

P.S. When putting the var in the Watch Window I see this value :
"DecryptedStringValue <---No " char at the end of the string

P.P.S Sorry for the multi-post, I had forgotten to add the other groups
Nov 23 '05 #1
2 1048
Most likely an error in your code, not the string. Here is my decryp logic.
Sorry, it is in C# but hope this helps

private byte[] Key;
private byte[] Vector;

public string Encrypt(string plainText)
{
byte[] data = new ASCIIEncoding().GetBytes(plainText);

RijndaelManaged crypto = new RijndaelManaged();
ICryptoTransform encryptor = crypto.CreateEncryptor(Key, Vector);

MemoryStream memoryStream = new MemoryStream();
CryptoStream crptoStream = new CryptoStream(memoryStream, encryptor,
CryptoStreamMode.Write);

crptoStream.Write(data, 0, data.Length);
crptoStream.FlushFinalBlock();

crptoStream.Close();
memoryStream.Close();

return Convert.ToBase64String(memoryStream.ToArray());
}

public string Decrypt(string encryptedText)
{
byte[] cipher = Convert.FromBase64String(encryptedText);

RijndaelManaged crypto = new RijndaelManaged();
ICryptoTransform encryptor = crypto.CreateDecryptor(Key, Vector);

MemoryStream memoryStream = new MemoryStream(cipher);
CryptoStream crptoStream = new CryptoStream(memoryStream, encryptor,
CryptoStreamMode.Read);

byte[] data = new byte[cipher.Length];
int dataLength = crptoStream.Read(data, 0, data.Length);

memoryStream.Close();
crptoStream.Close();

return (new ASCIIEncoding()).GetString(data, 0, dataLength);
}
<<<

--
Andrew Robinson
www.binaryocean.com
www.bellinghamdotnet.org
"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> wrote in message
news:ue**************@TK2MSFTNGP09.phx.gbl... Hi,
I encrypted a string using the RijndaelManaged class.

When decrypted, it happens that the string is longer then the original,
but
the exceeding chars are nothing (string.chars(indexOfExceedingChars) is
nothing)

To correct the problem, I used SomeOtherStringVar = trim(DecryptedString)

The problem is the following: Trim(DecryptedString) returns the string
without the exceeding chars, but SomeOtherStringVar still contains them
after the assignation. Should they not be removed?!?

I dont understand, can someone enlight me please?

Thanks

P.S. When putting the var in the Watch Window I see this value :
"DecryptedStringValue <---No " char at the end of the string

P.P.S Sorry for the multi-post, I had forgotten to add the other groups

Nov 23 '05 #2
<"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM>> wrote:
I encrypted a string using the RijndaelManaged class.

When decrypted, it happens that the string is longer then the original, but
the exceeding chars are nothing (string.chars(indexOfExceedingChars) is
nothing)

To correct the problem, I used SomeOtherStringVar = trim(DecryptedString)

The problem is the following: Trim(DecryptedString) returns the string
without the exceeding chars, but SomeOtherStringVar still contains them
after the assignation. Should they not be removed?!?
No - strings are immutable.
See http://www.pobox.com/~skeet/csharp/strings.html
I dont understand, can someone enlight me please?

P.S. When putting the var in the Watch Window I see this value :
"DecryptedStringValue <---No " char at the end of the string
As Andrew said, it's almost impossible to know why your code is failing
without seeing your code - but it's very likely to be a bug in your
code rather than in .NET.
P.P.S Sorry for the multi-post, I had forgotten to add the other groups


Actually, just posting to a single group would probably have been a
better idea in the first place, IMO...

--
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
Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
0
by: Tom Warren | last post by:
I found a c program called similcmp on the net and converted it to vba if anybody wants it. I'll post the technical research on it if there is any call for it. It looks like it could be a useful...
10
by: Mark Jerde | last post by:
I'm trying to learn the very basics of using an unmanaged C++ DLL from C#. This morning I thought I was getting somewhere, successfully getting back the correct answers to a C++ " int SumArray(int...
0
by: helldiversafe-news | last post by:
Hi all, I will use a apache soap service with an .net c# client and have a problem with an complex array: <?xml version='1.0' encoding='UTF-8'?> <SOAP-ENV:Envelope...
4
by: PSL | last post by:
Hi, I am going through the training C# For Programmers made by TestOut and like the presentation. The only problem is that this tutorial has a nastie bug that renders this software practically...
7
by: ankitjain.bvcoe | last post by:
Hi i have the following problem in my design :::: i want to define an abstract class LogBuffer and derive two singleton classes from it i.e AlarmBuffer and FireWallBuffer.For this my design is...
39
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1)...
4
by: RThaden | last post by:
Hi all, I looked in several books, articles, etc. but did not find a solution to my problem. Maybe somebody out there can help a desperate, not toooo experienced programmer: I want to...
10
by: dolphin | last post by:
Hi All I have a question now. Can I use a string to create a object? For example ,I have a function void fun(cha *str) the str is a name of a type. If I call the function fun("int"),how do I...
2
by: swethak | last post by:
hi , i write the code in .htm file. It is in cgi-bin/searches/one.htm.In that i write a form submitting and validations.But validations are not worked in that .htm file. I used the same code in my...
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?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.