Re: Public Key Encryption with RSACryptoServiceProvider

From: Pieter Philippaerts (Pieter.nospam_at_mentalis.org)
Date: 06/25/04


Date: Fri, 25 Jun 2004 20:07:28 +0200


"AlBruAn" <AlBruAn@discussions.microsoft.com> wrote in message
> 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...
> 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.
> 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?

> 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



Relevant Pages

  • Re: Public Key Encryption with RSACryptoServiceProvider
    ... >> 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 ... I then call the Encrypt function, passing it the license number ...
    (microsoft.public.dotnet.security)
  • Re: RSA question
    ... I assume you want to encrypt these licence codes so ... A license code scheme generally wants the author to *SIGN* license ... the customer when his hardware needs replacing. ... is to put the licence code on the physical product so that it ...
    (sci.crypt)
  • Re: RSA - Public vs. Private Keys
    ... This is a common pattern for license software ... your client will send a unique machine hash to the ... will let us decrypt with a Public Key (or simply not ... |> RSA is intended to encrypt messages with public keys only. ...
    (microsoft.public.dotnet.security)
  • RE: Secure e-mail
    ... Yes, but GnuPG is licensed under the GPL, isn't it? ... > "You can encrypt your messages with PGP products " ... > the license, not sure how it works for educational institutes, they may ... > messages with PGP products (absolutely free). ...
    (Security-Basics)
  • Re: How to decrypt with an RSA public key (at all)
    ... then have the server encrypt the license with the client's ... public key, then the client decrypts it with it's private key. ...
    (microsoft.public.dotnet.framework.aspnet.security)