|
Hi all,
I have a question about encrypting string data with the RSACryptoServiceProvider class.
Look at the following C# code example:
<br />
string target = "String to be encrypted ... ";<br />
<br />
int kLength = 128;
<br />
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(kLength * 8);<br />
UTF8Encoding enc = new UTF8Encoding();<br />
<br />
byte[] bytesTmp1 = enc.GetBytes(target);<br />
byte[] encrypted = rsa.Encrypt(bytesTmp1, false);<br />
string encString = Convert.ToBase64String(encrypted);<br />
<br />
At rsa.Encrypt(), I get a CryptographicException with the message "unspecified error". This error only occurs, if the string size is greater than the size of the key, which is used in the RSA CSP. For example: If the key size is 128 byte and the string length ist greater than 117 bytes, the error occurs. With shorter strings (for example 117 bytes or less), no error is been thrown.
The limit is at kLength - 10, longer strings will provoke the exception.
What am I doing wrong? How can I solve this problem? In my application, strings can have any size, there is no limit. The RSA CSP must be able to encrypt every strings, independent of its size.
I'm happy about any idea, which could help me solving this.
Greetings
|
|
|
|
|
Can someone please post a small/simple working example of doing a callback in Managed C++?
Basically, I have a MC++ windows form client, and an unmanaged C++ DLL (which I wrote). I have a function in MC++ client that needs to get fired by the DLL as it "loops" thru records (it's basically looking to see if a
<stop> button click has fired in the client). I've found several different C#-client examples on CodeProject and CodeGuru (and have read MSDN docs on delegates, as well as chapters in several books dealing with P/Invoke), but can't seem to find a simple example of doing a callback with MC++ (using DllImport) and a C++ DLL. I've tried to duplicate
the C# examples in MC++, but can't seem to find a ombination that compiles & works.
I've been doing C++ for many years (on the Borland side), but am a relative "rookie" with .NET (and MC++) -- thus, part of the reason why the syntax and the process is not clicking in my brain (yet <g> ).
Thanks in advance...
A Ansari
|
|
|
|
|
Sounds like a MC++ question, not a C# one.
Christian Graus - C++ MVP
'Why don't we jump on a fad that hasn't already been widely discredited ?' - Dilbert
|
|
|
|
|
Seems like he accidentally posted twice in the C# forum instead of cross posting in the C++ forum...
---
Year happy = new Year(2007);
|
|
|
|
|
Can someone please post a small/simple working example of doing a callback in Managed C++?
Basically, I have a MC++ windows form client, and an unmanaged C++ DLL (which I wrote). I have a function in MC++ client that needs to get fired by the DLL as it "loops" thru records (it's basically looking to see if a
<stop> button click has fired in the client). I've found several different C#-client examples on CodeProject and CodeGuru (and have read MSDN docs on delegates, as well as chapters in several books dealing with P/Invoke), but can't seem to find a simple example of doing a callback with MC++ (using DllImport) and a C++ DLL. I've tried to duplicate
the C# examples in MC++, but can't seem to find a ombination that compiles & works.
I've been doing C++ for many years (on the Borland side), but am a relative "rookie" with .NET (and MC++) -- thus, part of the reason why the syntax and the process is not clicking in my brain (yet <g> ).
Thanks in advance...
|
|
|
|
|
Wrong forum, try "(Managed) C++/CLI"
|
|
|
|
|
Hi all,
I am now developing a program which can get data from third party device with using serial port.I am facing 2 problem.
1)I am using serial port which provide by .NET. But in the properties i cant find LinkerPort(the device which i communicate to have linker port). So,how can i add in this properties?
2)In my situation,i need to get 3 group of string buffer and will assign them to different string object(example A,B,C). I am refer to the example at code project (title : Serial communication in .NET 2.0).i need to do these action at the same time(in real time).My question is how can i get the 3 string buffer at the same time(possible?) and how to recognize them whether the first string buffer is belonging to object A and so on..
any hits are welcome,
thanks in advance
cocoonwls
|
|
|
|
|
Hello all,
First time post...so go easy on me
Here is what my problem is with the BackgroundWorker:
I have a list of files that I would like to go through and manipulate in the background, the problem I am having is how do I recover if one of those files has an error in it?
What I mean by recover is instead of raising an error, I would like to store the error in some list and move on to the next file and then when all the files are done I would like to write to a text box the files that had an error..Would I handle this in BackgroundWorkers RunWorkerCompleted? Because this is where an error goes when it occurs in the DoWork method. Basically after an error how can I get back into my for or while loop that iterates over the remaining files..starting at the next file...
Thanks
Alan
|
|
|
|
|
Use a try-catch-block inside your DoWork method.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Wow...Holy crap I never thought of that.....I was reading this article http://www.developerdotstar.com/community/node/671/print and it said not to use a try/catch block with the backgroundworker....but I just realized....they meant "Around the backgroundworker" not in the doWork method....Wow....Thank You
|
|
|
|
|
My pleasure
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I was actually going to say..." I am an idiot for not thinking that " but I read your sig.... and decided not too. Thanks again
|
|
|
|
|
I don`t t know how to write some information to file descrition , the class FileVesion just can get the inforamtion .
who can help me ?
thanks!
|
|
|
|
|
hi i have a small question.
how is it posible to abort an thread, inside the thread.
so what does i whant
<br />
while(true)<br />
{<br />
Thread thread = new Thread(new ThreadStart(myclass.functioninmyclass));<br />
thread.start();<br />
}<br />
<br />
public void functioninmyclass()<br />
{<br />
<br />
}<br />
<br />
|
|
|
|
|
Hello,
You could use "return;" to end the method, I think the thread will automatically stop after that.
All the best,
Martin
|
|
|
|
|
hi,
You can try this:
<br />
if (thread.IsAlive)<br />
{<br />
thread.Abort();<br />
}
all the best
|
|
|
|
|
When the top-level method of your thread's code comes to an end (by returning or reaching
end of method), the thread exits.
You really should try to let your thread finish up by itself, so use return, and let
all using blocks and finally blocks do the cleanup work.
In general Thread.Abort is not OK since that does not take care of any resources, locks,
etc that your thread possesses.
Luc Pattyn
|
|
|
|
|
HI,
I must implement a millesimale chronometer in C# on my pda… and I have studied the 3 types of timer inside framework .NET (the System.Windows.Forms.Timer, System.Timer (NOT AVAILABLE IN .NET CF) and System.Threading.Timer.
I have begun to test, obtaining strange turns out. The good old API function (GetTickCount) was much simple one to use and in little instructions, associating at the timer with interval of 1 millisecond, worked correctly, but now something does not return and it turns out obtained are not those obtained hopes to you.
Help me please ..
Alex
|
|
|
|
|
Honestly, I didn't get what your problem is and I think understanding your post is hard for everyone else too (no offense intended). Maybe you can rephrase your problem a bit to clear things up. Furthermore, it would be helpful to see the code in question.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I must develop a millesimale chronometer using the System.Threading.Timer or the System.Windows.Forms.Timer but I do not succeed to show the millesimi elapsed. In VB6 I have used the GetTickCount function, but in “.NET COMPACT FRAMEWORK” it is not supported.
How I can make?
Alex
|
|
|
|
|
Try DateTime.Now.Ticks .
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I Try this ..
-- Example C#:
long lInit, lDiff;
//Start function
lInit = DateTime.Now.Ticks;
//Event timer (interval 1 millisecond)
lDiff = (DateTime.Now.Ticks - lInit) / 1000;
But the result is different from example below:
-- Example VB6:
//Start function
lInit = GetTickCount()
//Event timer (interval 1 millisecond)
lDiff = (GetTickCount() - lInit) / 1000
I must view any millisecond elapsed on interval ...
Alex
|
|
|
|
|
The Ticks property returns the number of 100-Nanosecond-Intervals since a specific date, so you should divide by 10000 I think.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
I have tried but it does not work correctly…
Alex
|
|
|
|
|
AlexB47 wrote: does not work correctly…
What does that mean? How does the calculation results differ?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|