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 2 1044
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
<"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM).
In this month's session, the creator of the excellent VBE...
|
by: MeoLessi9 |
last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: marcoviolo |
last post by:
Dear all,
I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
| | |