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

  • Thread starter Thread starter ThunderMusic
  • Start date Start date
T

ThunderMusic

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
 
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);
}


<<<
 
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...
 
Back
Top