Click here to Skip to main content
16,011,647 members
Home / Discussions / C#
   

C#

 
AnswerRe: Logging into a site Pin
Pete O'Hanlon26-Jan-07 1:56
mvePete O'Hanlon26-Jan-07 1:56 
GeneralRe: Logging into a site Pin
sharpiesharpie26-Jan-07 2:35
sharpiesharpie26-Jan-07 2:35 
AnswerRe: Logging into a site Pin
Ravi Bhavnani26-Jan-07 4:18
professionalRavi Bhavnani26-Jan-07 4:18 
GeneralRe: Logging into a site Pin
sharpiesharpie26-Jan-07 4:39
sharpiesharpie26-Jan-07 4:39 
GeneralRe: Logging into a site Pin
Ravi Bhavnani26-Jan-07 4:47
professionalRavi Bhavnani26-Jan-07 4:47 
GeneralRe: Logging into a site Pin
sharpiesharpie26-Jan-07 7:06
sharpiesharpie26-Jan-07 7:06 
GeneralRe: Logging into a site Pin
Ravi Bhavnani26-Jan-07 7:12
professionalRavi Bhavnani26-Jan-07 7:12 
QuestionCryptographicException: Unspecified Error!? Pin
xeri25-Jan-07 23:05
xeri25-Jan-07 23:05 
Hi all,

I have a question about encrypting string data with the RSACryptoServiceProvider class.

Look at the following C# code example:

<br />
// The target string<br />
string target = "String to be encrypted ... ";<br />
<br />
// Key length (in byte), which is used by the RSA CSP<br />
int kLength = 128; // Default<br />
<br />
// The RSA CSP<br />
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(kLength * 8);<br />
// Encoding<br />
UTF8Encoding enc = new UTF8Encoding();<br />
<br />
// Convert the string into a byte array<br />
byte[] bytesTmp1 = enc.GetBytes(target);<br />
// Encrypting<br />
byte[] encrypted = rsa.Encrypt(bytesTmp1, false);<br />
// Reconvert the array into a string<br />
string encString = Convert.ToBase64String(encrypted);<br />
<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
QuestionCan u give me a working Example Pin
A . Ansari25-Jan-07 23:02
A . Ansari25-Jan-07 23:02 
AnswerRe: Can u give me a working Example Pin
Christian Graus25-Jan-07 23:04
protectorChristian Graus25-Jan-07 23:04 
JokeRe: Can u give me a working Example Pin
Guffa25-Jan-07 23:54
Guffa25-Jan-07 23:54 
QuestionCan u give me a working Example Pin
A . Ansari25-Jan-07 23:02
A . Ansari25-Jan-07 23:02 
AnswerRe: Can u give me a working Example Pin
stancrm26-Jan-07 0:29
stancrm26-Jan-07 0:29 
QuestionSerial Communication Pin
cocoonwls25-Jan-07 23:02
cocoonwls25-Jan-07 23:02 
QuestionBackgroundWorker: Recover from Error Pin
aread2225-Jan-07 22:27
aread2225-Jan-07 22:27 
AnswerRe: BackgroundWorker: Recover from Error Pin
Stefan Troschuetz25-Jan-07 22:32
Stefan Troschuetz25-Jan-07 22:32 
GeneralRe: BackgroundWorker: Recover from Error Pin
aread2225-Jan-07 22:35
aread2225-Jan-07 22:35 
GeneralRe: BackgroundWorker: Recover from Error Pin
Stefan Troschuetz25-Jan-07 22:40
Stefan Troschuetz25-Jan-07 22:40 
GeneralRe: BackgroundWorker: Recover from Error Pin
aread2225-Jan-07 22:42
aread2225-Jan-07 22:42 
QuestionHow to write information to file descritpion Pin
jiangwm_shy200525-Jan-07 22:01
jiangwm_shy200525-Jan-07 22:01 
QuestionThread and how to stop Pin
gigo2k625-Jan-07 22:00
gigo2k625-Jan-07 22:00 
AnswerRe: Thread and how to stop Pin
Martin#25-Jan-07 22:08
Martin#25-Jan-07 22:08 
AnswerRe: Thread and how to stop Pin
cocoonwls25-Jan-07 22:30
cocoonwls25-Jan-07 22:30 
AnswerRe: Thread and how to stop Pin
Luc Pattyn25-Jan-07 23:58
sitebuilderLuc Pattyn25-Jan-07 23:58 
QuestionC#, Timer and GetTickCount on Compact Framework Pin
AlexB4725-Jan-07 21:48
AlexB4725-Jan-07 21:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.