Re: Encrypting using RSA private Key
- From: "Marcello Cantelmo" <marcello___AT___cantelmosoftware___DOT___com>
- Date: Thu, 10 Apr 2008 13:41:35 +0200
Hi Jeronimo Bertran,
not with .NET! the answer is YES but only if you rewrite the rsa algo :-D
....you need a BigInteger library ;-)
P = 1st large prime number
Q = 2nd large prime number
E = Public Exponent: 3 (fast operation), 65537 (secure) (or random number
which must: GCD(E, (P-1)*(Q-1))==1)
N = Public Modulus, N=P*Q
D = Private Exponent: D=E^(-1) mod ((P-1)*(Q-1))
{N,E}=publickey
{D}=privatekey
standard use:
-------------
encryption: C=M^E mod N with M<N
decryption: M=C^D mod N
the inverse use of rsa :-o is:
encryption: C=M^D mod N with M<N
decryption: M=C^E mod N
^ = PowerOf
HTH
--
Marcello Cantelmo
www.cantelmosoftware.com
Hi,
Is it possible to encrypt using the RSA private key and decrypt using the
public key? I am able to do the opposite but when I try to decrypt using
the private key I get a "Bad Key" Exception. Here is an example:
rsa = new RSACryptoServiceProvider();
RSAParameters publicKey = rsa.ExportParameters(false);
RSAParameters privateKey = rsa.ExportParameters(true);
byte[] testPlainData = new byte[] { 0x01, 0x02, 0x03 };
rsa.ImportParameters(publicKey);
byte[] enc = rsa.Encrypt(testPlainData, false);
rsa.ImportParameters(privateKey);
byte[] plain = rsa.Decrypt(enc, false);
enc = rsa.Encrypt(testPlainData, false);
rsa.ImportParameters(publicKey);
rsa.Decrypt(enc, false);
The first encryption and decryption work fine. The second encryption
(using the private key) seems to work but the decryption using the public
key throws the exception.
Thanks,
Jeronimo
.
- References:
- Encrypting using RSA private Key
- From: Jeronimo Bertran
- Encrypting using RSA private Key
- Prev by Date: Re: Validate user permission
- Next by Date: How do I programmatically install a SSL Certificate to a WinCE 5.0 Device?
- Previous by thread: Re: Encrypting using RSA private Key
- Next by thread: "The Local Security Authority cannot be contacted" when running as service
- Index(es):
Relevant Pages
|