Re: No way to encrypt with private key in C#?
- From: Lasse Vågsæther Karlsen <lasse@xxxxxxxxxxx>
- Date: Mon, 04 Feb 2008 16:00:41 +0100
Peter Webb wrote:
"Alun Harford" <devnull@xxxxxxxxxxxxxxxxx> wrote in message news:%23n7ijGuZIHA.484@xxxxxxxxxxxxxxxxxxxxxxxAlun Harford wrote:Sin Jeong-hun wrote:Hello.
As far as my naive textbook knowledge goes;
1)if a file is encrypted with the private key, then it can be
decrypted with the public key,
2)if a file is encrypted with the public key, then it can be decrypted
with the private key.
Only (2) is true.
Re-reading the question, they're both true.
No.
1. is not true. I think the OP (and possibly yourself) is confused by the fact that most real systems have two public and two private keys - one for each end of the link. If a file encrypted with the private key could be decrypted with just the public key, it would be a pretty piss-poor security mechanism. What actually happens is that the sender encrypts with the recipient's public key, not his own (public or private) key.
You should be able to run data through the RSA algorithm both ways, when thinking about the keys.
The two ways are usually called encryption and signing, from public to private and back again.
The fact that signing *typically* works on a hash does not mean that it can only work on a hash, and this is what the .NET algorithm seems to be limited to. There is nothing prohibiting an application using RSA to "encrypt" the entire file using the private key and release it, so that everyone that wants to use it must first decrypt it with the public key. Since most people associate cryptography with secure information hiding, this usually rings wrong.
The reason this isn't typically done is usually both practicality and performance. To use the file, *everyone* must decrypt it. Decryption using RSA is much slower than ordinary symmetrical encryption algorithms.
So to first take a hash of the file and then encrypt that using the private key (in fact, signing the data), is both more practical (only people that wants to verify the signature needs to decrypt it) and speedier (much less data to run through like this).
If you look up RSA on wikipedia and read the signing messages section, you'll see the following text:
"Suppose Alice wishes to send a signed message to Bob. She produces a hash value of the message, raises it to the power of d mod n (as she does when decrypting a message), and attaches it as a "signature" to the message. When Bob receives the signed message, he raises the signature to the power of e mod n (as he does when encrypting a message), and compares the resulting hash value with the message's actual hash value."
The important thing to notice is that with a private and public key of the RSA algorithm, the two ways are *typically* called encryption and signing, because people tend to associate cryptography with "hiding information securely".
Another source of information is this:
http://www.di-mgt.com.au/rsa_alg.html
If you read through encryption/decryption and digital signing/signature verification you'll notice it's the exact same thing, except for which key is being used, and the addition of a message digest.
Especially noteworth is the 5th note, which reads:
"Decryption and signing are identical as far as the mathematics is concerned as both use the private key. Similarly, encryption and verification both use the same mathematical operation with the public key."
While I would typically still hold that producing a hash and signing that using the RSA algorithm with a private key, the .NET implementation is still not as useful to every and all cases as it could've been, if it had implemented both ways identicaly, and just documented how to sign and verify using one of the many hash algorithms also provided.
--
Lasse Vågsæther Karlsen
mailto:lasse@xxxxxxxxxxx
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
.
- References:
- No way to encrypt with private key in C#?
- From: Sin Jeong-hun
- Re: No way to encrypt with private key in C#?
- From: Alun Harford
- Re: No way to encrypt with private key in C#?
- From: Alun Harford
- Re: No way to encrypt with private key in C#?
- From: Peter Webb
- No way to encrypt with private key in C#?
- Prev by Date: Re: Get/Set vs Public Variables
- Next by Date: Re: Creating a password login
- Previous by thread: Re: No way to encrypt with private key in C#?
- Next by thread: Re: No way to encrypt with private key in C#?
- Index(es):
Relevant Pages
|