HighTechTalks DotNet Forums  

Re: Public Key Encryption with RSACryptoServiceProvider

Dotnet Security microsoft.public.dotnet.security


Discuss Re: Public Key Encryption with RSACryptoServiceProvider in the Dotnet Security forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Pieter Philippaerts
 
Posts: n/a

Default Re: Public Key Encryption with RSACryptoServiceProvider - 06-25-2004 , 02:07 PM






"AlBruAn" <AlBruAn (AT) discussions (DOT) microsoft.com> wrote in message
Quote:
I'm attempting to use the RSACryptoServiceProvider class to encrypt some
licensing information I'm storing in SQL Server, but I'm encountering a "Bad
Data" CryptographicException when I try decrypting the data and wonder how I
can get around this issue. I'm not storing any information in SQL Server
until I can get the mechanics of encryption working properly. Anyway...
Quote:
I've generated a pair of public and private keys using
RSACryptoServiceProvider's ToXml function, passing false and true arguments,
respectively, to it. I then persist these keys to the root directory of my
C: drive using an XmlTextWriter.
Quote:
When it's time to encrypt a license number, I create a new instance of the
RSACryptoServiceProvider object and read in the public key using its FromXml
function. I then call the Encrypt function, passing it the license number
and specifying no OAEP padding. My final step is to persist the encrypted
values to a separate file in the root directory of my C: drive.

From your description, there doesn't seem to be an abvious error. Could you
post the source code you're using so we can take a closer look?

Quote:
Even tho' I'm using the string "123" as my "license number" and using the
same
public key, I'm getting different values for the encrypted "license
number".

This is normal; whenever you encrypt something, the RSACryptoServiceProvider
will add a special padding to your data to make sure the length is equal to
the modulus size of your public key. This padding consists mostly of random
bytes, hence the difference.

Regards,
Pieter Philippaerts




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.