RSA frustrations - encrypt with private, decrypt with public - possible?

RSA frustrations - encrypt with private, decrypt with public - possible?

Secure Home | Search | About
 Microsoft Applications Security    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content add this group's latest topics to your Google content
Subject Author Date
RSA frustrations - encrypt with private, decrypt with public - possible? mRislan 10-24-2005
Posted by mRislan on October 24, 2005, 9:03 pm
If you were  Registered and logged in, you could reply and use other advanced thread options
OK - I've seen signs of numerous people being stuck pounding their
heads against desks with the same problem as I have, but I haven't
seen any definitive answers on the subject.

I don't need lectures on Alice and Bob; I'd prefer if someone give me
a simple answer to what is, I think, a simple question. Can the
following be implemented with framework Cryptography methods (or even
interop on underlying Win32 DLLs)?

For e.g. software registration purposes, it seems simple and effective
to do the following:

-User with name "Foo" requests license.
-Provider hashes "Foo" & some other license info, encrypts with
private key, delivers it.
-User has public key (distributed with application), and decrypts hash
with it. Program is happy and works.

Yes, program code can still be modified to subvert this in various
ways - what can't, really?. But short of that, license information
itself cannot (realistically) be forged assuming a sufficiently large
keysize.

It seems clear that RSACryptoServiceProvider can't do this, and
effectively only works the other way round. Nevermind CSP - I don't
want anything to do with the 'keystore', I simply want server to sign,
and client to decrypt with only the public key rolled up and
obfuscated in the assembly delivered to them.

SignData and VerifyData work in the direction I want, but don't seem
sufficient - I want to encrypt / decrypt a small amount of arbitrary
data, not leave it in the clear and merely sign a hash on it.

Googling for "decrypt with public" and a hundred other variants,
numerous people are answering people with the same question to the
effect of "this is the wrong way to use RSA", "use the keystore",
"distribute private key, hide and encrypt with public". The latter
response at least makes me feel certain that I am not the world's most
crypto-challenged individual after all... but I guess the root problem
is that most responders are not paying attention to the quite clear
descriptions of usage (ie as a software licensing mechanism) before
they start talking about Alice and Bob and which directions make
sense.

Clearly programs have used and continue to use RSA for precisely this
kind of protection scheme for some time. It has been done in the
pre-managed Win32 world for some time, and the approach seems to be
becoming popular on other platforms:

http://aquaticmac.com/
http://macromates.com/sigpipe/archives/2004/09/05/using-openssl-for-license-keys/#more-5

RSACryptoServiceProvider looks to be a dead end for my purposes.

Is there any way to massage the kind of functionality I want out of
the framework, or am I going to have to do the now so-very-familiar
DotNet dance of reinventing the wheel? Please, somebody answer this
clearly and definitively - so that nobody else has to waste days upon
days swimming through documentation and toy code, getting nowhere
fast.

Risl.

Posted by William Stacey [MVP] on October 24, 2005, 10:09 pm
If you were  Registered and logged in, you could reply and use other advanced thread options
MS has a free bundle that will do this for you at
http://sharewarestarterkit.com/

If you do want to do it yourself for some reason, the general idea:
1) Create your license, including the machine hash of the machine that is
allowed to run it. If you don't include a machine hash, then anyone can
send the valid license around and use it.
2) Hash and sign it with your RSA private key. This proves it is valid and
from your service side (i.e. private key side).
3) On client startup, find a license and verify the lic signature using
VerifyData as you said. Verifing the sig is the only function, in
RSACrypto, that can decrypt using the public key.

What do you want to decrypt in the license besides the license sig? It may
not be required or there may be another way to refactor your license
protocol. Please expand.

--
William Stacey [MVP]

> OK - I've seen signs of numerous people being stuck pounding their
> heads against desks with the same problem as I have, but I haven't
> seen any definitive answers on the subject.
>
> I don't need lectures on Alice and Bob; I'd prefer if someone give me
> a simple answer to what is, I think, a simple question. Can the
> following be implemented with framework Cryptography methods (or even
> interop on underlying Win32 DLLs)?
>
> For e.g. software registration purposes, it seems simple and effective
> to do the following:
>
> -User with name "Foo" requests license.
> -Provider hashes "Foo" & some other license info, encrypts with
> private key, delivers it.
> -User has public key (distributed with application), and decrypts hash
> with it. Program is happy and works.
>
> Yes, program code can still be modified to subvert this in various
> ways - what can't, really?. But short of that, license information
> itself cannot (realistically) be forged assuming a sufficiently large
> keysize.
>
> It seems clear that RSACryptoServiceProvider can't do this, and
> effectively only works the other way round. Nevermind CSP - I don't
> want anything to do with the 'keystore', I simply want server to sign,
> and client to decrypt with only the public key rolled up and
> obfuscated in the assembly delivered to them.
>
> SignData and VerifyData work in the direction I want, but don't seem
> sufficient - I want to encrypt / decrypt a small amount of arbitrary
> data, not leave it in the clear and merely sign a hash on it.
>
> Googling for "decrypt with public" and a hundred other variants,
> numerous people are answering people with the same question to the
> effect of "this is the wrong way to use RSA", "use the keystore",
> "distribute private key, hide and encrypt with public". The latter
> response at least makes me feel certain that I am not the world's most
> crypto-challenged individual after all... but I guess the root problem
> is that most responders are not paying attention to the quite clear
> descriptions of usage (ie as a software licensing mechanism) before
> they start talking about Alice and Bob and which directions make
> sense.
>
> Clearly programs have used and continue to use RSA for precisely this
> kind of protection scheme for some time. It has been done in the
> pre-managed Win32 world for some time, and the approach seems to be
> becoming popular on other platforms:
>
> http://aquaticmac.com/
>
http://macromates.com/sigpipe/archives/2004/09/05/using-openssl-for-license-keys/#more-5
>
> RSACryptoServiceProvider looks to be a dead end for my purposes.
>
> Is there any way to massage the kind of functionality I want out of
> the framework, or am I going to have to do the now so-very-familiar
> DotNet dance of reinventing the wheel? Please, somebody answer this
> clearly and definitively - so that nobody else has to waste days upon
> days swimming through documentation and toy code, getting nowhere
> fast.
>
> Risl.



Posted by Alun Jones on October 24, 2005, 11:10 pm
If you were  Registered and logged in, you could reply and use other advanced thread options
I'm sorry to have to tell you this, but what you're asking for really _is_
the wrong way around.

Encrypting with the private key is not encrypting. It is, at the very best,
encoding, because your public key is ... available to everyone in the whole
world.

What is the purpose of "encrypting with the private key"?

Is it to prove that the message comes from you? If so, SIGN THE MESSAGE.

Is it to prevent other people from decrypting the message? If so, ENCRYPT
THE MESSAGE WITH THE RECIPIENT'S PUBLIC KEY. [Or, more usually, and
particularly for longer-than-trivial messages, encrypt a symmetric key with
the recipient's public key, and use the symmetric key to encrypt the
message.]

Is it to do both? SIGN AND ENCRYPT, as above.

"Encrypting with the private key", while mathematically possible, is
tantamount to screaming "I DON'T UNDERSTAND WHAT I'M DOING WITH
CRYPTOGRAPHY", to anyone who's taken more than an overview course in crypto.
Is that really the message you want to send?

Alun.
~~~~
--
[Please don't email posters, if a Usenet response is appropriate.]
--
Texas Imperial Software | Find us at http://www.wftpd.com or email
23921 57th Ave SE | alun@wftpd.com.
Washington WA 98072-8661 | WFTPD, WFTPD Pro are Windows FTP servers.
Fax/Voice +1(425)807-1787 | Try our NEW client software, WFTPD Explorer.


> OK - I've seen signs of numerous people being stuck pounding their
> heads against desks with the same problem as I have, but I haven't
> seen any definitive answers on the subject.
>
> I don't need lectures on Alice and Bob; I'd prefer if someone give me
> a simple answer to what is, I think, a simple question. Can the
> following be implemented with framework Cryptography methods (or even
> interop on underlying Win32 DLLs)?
>
> For e.g. software registration purposes, it seems simple and effective
> to do the following:
>
> -User with name "Foo" requests license.
> -Provider hashes "Foo" & some other license info, encrypts with
> private key, delivers it.
> -User has public key (distributed with application), and decrypts hash
> with it. Program is happy and works.
>
> Yes, program code can still be modified to subvert this in various
> ways - what can't, really?. But short of that, license information
> itself cannot (realistically) be forged assuming a sufficiently large
> keysize.
>
> It seems clear that RSACryptoServiceProvider can't do this, and
> effectively only works the other way round. Nevermind CSP - I don't
> want anything to do with the 'keystore', I simply want server to sign,
> and client to decrypt with only the public key rolled up and
> obfuscated in the assembly delivered to them.
>
> SignData and VerifyData work in the direction I want, but don't seem
> sufficient - I want to encrypt / decrypt a small amount of arbitrary
> data, not leave it in the clear and merely sign a hash on it.
>
> Googling for "decrypt with public" and a hundred other variants,
> numerous people are answering people with the same question to the
> effect of "this is the wrong way to use RSA", "use the keystore",
> "distribute private key, hide and encrypt with public". The latter
> response at least makes me feel certain that I am not the world's most
> crypto-challenged individual after all... but I guess the root problem
> is that most responders are not paying attention to the quite clear
> descriptions of usage (ie as a software licensing mechanism) before
> they start talking about Alice and Bob and which directions make
> sense.
>
> Clearly programs have used and continue to use RSA for precisely this
> kind of protection scheme for some time. It has been done in the
> pre-managed Win32 world for some time, and the approach seems to be
> becoming popular on other platforms:
>
> http://aquaticmac.com/
>
http://macromates.com/sigpipe/archives/2004/09/05/using-openssl-for-license-keys/#more-5
>
> RSACryptoServiceProvider looks to be a dead end for my purposes.
>
> Is there any way to massage the kind of functionality I want out of
> the framework, or am I going to have to do the now so-very-familiar
> DotNet dance of reinventing the wheel? Please, somebody answer this
> clearly and definitively - so that nobody else has to waste days upon
> days swimming through documentation and toy code, getting nowhere
> fast.
>
> Risl.



Posted by Roger Abell [MVP] on October 25, 2005, 12:58 am
If you were  Registered and logged in, you could reply and use other advanced thread options
What you outline works, as far as the mathematics of the crypto goes,
but anyone grabbing off the wire the license blob you send will have a
license (as they can get your public key).

--
Roger Abell
Microsoft MVP (Windows Server : Security)
MCDBA, MCSE W2k3+W2k+Nt4
> OK - I've seen signs of numerous people being stuck pounding their
> heads against desks with the same problem as I have, but I haven't
> seen any definitive answers on the subject.
>
> I don't need lectures on Alice and Bob; I'd prefer if someone give me
> a simple answer to what is, I think, a simple question. Can the
> following be implemented with framework Cryptography methods (or even
> interop on underlying Win32 DLLs)?
>
> For e.g. software registration purposes, it seems simple and effective
> to do the following:
>
> -User with name "Foo" requests license.
> -Provider hashes "Foo" & some other license info, encrypts with
> private key, delivers it.
> -User has public key (distributed with application), and decrypts hash
> with it. Program is happy and works.
>
> Yes, program code can still be modified to subvert this in various
> ways - what can't, really?. But short of that, license information
> itself cannot (realistically) be forged assuming a sufficiently large
> keysize.
>
> It seems clear that RSACryptoServiceProvider can't do this, and
> effectively only works the other way round. Nevermind CSP - I don't
> want anything to do with the 'keystore', I simply want server to sign,
> and client to decrypt with only the public key rolled up and
> obfuscated in the assembly delivered to them.
>
> SignData and VerifyData work in the direction I want, but don't seem
> sufficient - I want to encrypt / decrypt a small amount of arbitrary
> data, not leave it in the clear and merely sign a hash on it.
>
> Googling for "decrypt with public" and a hundred other variants,
> numerous people are answering people with the same question to the
> effect of "this is the wrong way to use RSA", "use the keystore",
> "distribute private key, hide and encrypt with public". The latter
> response at least makes me feel certain that I am not the world's most
> crypto-challenged individual after all... but I guess the root problem
> is that most responders are not paying attention to the quite clear
> descriptions of usage (ie as a software licensing mechanism) before
> they start talking about Alice and Bob and which directions make
> sense.
>
> Clearly programs have used and continue to use RSA for precisely this
> kind of protection scheme for some time. It has been done in the
> pre-managed Win32 world for some time, and the approach seems to be
> becoming popular on other platforms:
>
> http://aquaticmac.com/
>
http://macromates.com/sigpipe/archives/2004/09/05/using-openssl-for-license-keys/#more-5
>
> RSACryptoServiceProvider looks to be a dead end for my purposes.
>
> Is there any way to massage the kind of functionality I want out of
> the framework, or am I going to have to do the now so-very-familiar
> DotNet dance of reinventing the wheel? Please, somebody answer this
> clearly and definitively - so that nobody else has to waste days upon
> days swimming through documentation and toy code, getting nowhere
> fast.
>
> Risl.



Similar ThreadsPosted
Public - Private key June 28, 2007, 11:46 am
public and private cert January 8, 2008, 12:05 am
help understanding private/public certs September 2, 2007, 5:30 pm
Public Keys, Private Keys, & Certificates January 29, 2006, 10:16 am
Encrypt This September 29, 2006, 9:03 pm
Best way to Encrypt on streaming files? June 12, 2006, 2:59 pm
Sign and encrypt mail February 21, 2008, 12:31 am
RE: how to encrypt entire drive? November 26, 2008, 6:26 pm
How do I encrypt a whole (external) USB harddisc (under Win2000 and WinXP)? July 11, 2005, 9:13 am
Unable to un-encrypt a folder using Windows encryption - access de August 27, 2008, 7:39 pm

The site map in XML format XML site map

Contact Us | Privacy Policy