Re: RSACryptoServiceProvider - Decrypting then Encrypting

From: Peter McEvoy (peter_mcevoy_at_excite.com)
Date: 07/01/03


Date: 1 Jul 2003 10:33:06 -0700


Paul,
        I read with interest your recent message to aspnet.security:
http://groups.google.ie/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=Owh3dOXODHA.1024%40TK2MSFTNGP12.phx.gbl&rnum=16&prev=/groups%3Fq%3D%2522Bad%2BData%2522%2BCryptographicException%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26start%3D10%26sa%3DN

I have been trawling the net for the last day looking for a way to
encrypt a message using the PRIVATE key and decrypt using the PUBLIC
key as well, and I was wondering if you had received any follow-ups on
your question?

My own reasons for doing this are because I want to be able to encrypt
a string that can only be decrypted using the public key that I
provide: I will be distributing the public key within my .Net
application - distributing the key pair is obviously not a runner...

I know this is mathematically (and crytographically) possible, and
have read numerous threads on sci.crypt that assure this. In fact,
crytograpic siging does this (Singing actually encrypts a _hash_ of
the data using the private key - verifying the sig means decrypting
the encrypted hash using the public key and comparing the decrypted
hash with a generated hash), so I know there is enough info in the
public key to decrypt a message encrypted with the private key)

Where I am right now is this:
- .Net pukes if you try to decrypt using a key that is public
- .Net will only decrypt using a key that contains key-pair
information
- .Net encrypts using the public key info of the key
- Public keys contain only Modulus (128 bit) and Exponent (3bit)
information
- Key pairs contain lots of other fields, but the only other field of
size 128bit is the "D" parameter
- When encrypting, I create a new RSA key pair, and assign the Modulus
param the "D" param value of my stored private key (the one I want to
keep secret in the office)
- When decrypting, I create a new RSA Key pair, and assign the "D"
param the value of the Modulus of the public key (the public key is an
embedded resource in the application)

To my mind, this "should" work, but I am also getting a "Bad data"
message...

(BTW, I was also getting a "Bad Data" message when I incorrectly
converted the byte[] to strings using ASCIIEncoding.ASCII.GetBytes,
when it converts correctly if I use Convert.ToBase64String (to convert
the byte[] to a string) and Convert.FromBase64String (to convert from
a string to a byte[]).

Have you had any sucess with this since you posted your message?

All the best,
Pete



Relevant Pages

  • Re: More on learning "Public Key Authentication"
    ... let me say that in public key ... > encrypt the result with Alice's public key. ... > is sent to Alice who decrypts the message with her private key (which ... encrypted with my private key and they can then decrypt it with the ...
    (comp.sys.mac.system)
  • Re: Public - Private key
    ... As to what could be a very small private key and veyr small public key so ... decrypt A1 and likewise A1 can only decrypt P1. ... When PC1 communicates securely with PC2, PC1 will encrypt the data using the ...
    (microsoft.public.security)
  • Re: DECRYPT with PUBLIC key (how to?)
    ... values in my application which would be decoded with my own public key which ... This is a very stupid thing to think that you can encrypt with private ... Private key operations often uses CRT ... Signature schemes and Encryption schemes have completely different ...
    (microsoft.public.dotnet.security)
  • RSA frustrations - encrypt with private, decrypt with public - possible?
    ... -User with name "Foo" requests license. ... -User has public key, ... sufficient - I want to encrypt / decrypt a small amount of arbitrary ... "distribute private key, ...
    (microsoft.public.security)
  • RSA frustrations - encrypt with private, decrypt with public - possible?
    ... -User with name "Foo" requests license. ... -User has public key, ... sufficient - I want to encrypt / decrypt a small amount of arbitrary ... "distribute private key, ...
    (microsoft.public.dotnet.security)