470,632 Members | 2,706 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

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 976
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mahesh Devjibhai Dhola | last post: by
10 posts views Thread by Mark Jerde | last post: by
reply views Thread by helldiversafe-news | last post: by
7 posts views Thread by ankitjain.bvcoe | last post: by
39 posts views Thread by Martin Jørgensen | last post: by
10 posts views Thread by dolphin | last post: by
2 posts views Thread by swethak | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.