1

While reading about DKIM I saw that the sender's private key is used to encrypt a hash, later decrypted by the recipient using the sender's public key.

This is exactly the other way compared to encrypting a message.

Since both private and public keys can be used to encrypt a message (a mail or a hash for the two cases above), how different are they?

  • Why cannot they be used interchangeably?
  • Is the encrypting algorithm different depending on which key is used (and - presumably - the strength of the generated cryptotext is different?)

3 Answers 3

7

Public and private key in a key pair are distinct aspects of an underlying mathematical structure.

Let's take some examples:

  • In RSA, the public key consists in a big composite integer n (called the modulus), and a (usually short) odd integer (the "public exponent"). The private key is, ultimately, the knowledge of the prime factors of n. In practice, n = pq for two big primes p and q, and the private key is p and q.

  • In ECDSA, we operate over an elliptic curve, which is a weird mathematical animal that contains "points". A curve is a group of a certain size q. The private key x is a non-zero integer modulo q (that is, an integer between 1 and q-1); the public key is a point on the curve, which happens to be the result of applying the group law x-1 times on a conventional, fixed point (called the "generator").

In both cases, there is a strong mathematical relation between the private and public key, but they still are very distinct things. Also, the structure on which asymmetric cryptography works depends on the algorithm, and there is quite some variety.

Last but not least, DKIM is not about encryption. It is a mechanism that uses signatures. You apparently stumbled upon one of the many texts that purport to explain signatures as "encrypting the hash". Be aware that all these explanations are both confusing and wrong.

5
  • 1
    "they still are very distinct things" - still, it is possible to encrypt with both of them (and decrypt with the other, at least with RSA). I was curious about the implications of using one or the other.
    – WoJ
    Commented Mar 23, 2016 at 16:37
  • Re: DKIM: I know that this is a signature, but isn't there an encryption component (when encrypting the hash - which as you mention is wrong?). <del>This is what Wikipedia claims, at least (which does not mean that it is correct, but for technical information it usually is)</del> update: the answer coming from a PhD in cryptography from ENS beats Wikipedia :)
    – WoJ
    Commented Mar 23, 2016 at 16:40
  • 1
    No, it is not possible to encrypt with both of them. It is possible to use both public key and private key interchangeably only in the case of not-really-RSA, which is like RSA except that you removed the parts that actually make it decently robust. Some people claim that it is "textbook RSA", in the sense that a hamburger is a "textbook cow". Commented Mar 23, 2016 at 16:40
  • The signature generation process outputs a signature, which cannot be called "encryption", if only because the input data (hashed message) can be recovered from the signature using only public information (namely, the public key). If the data can be recovered using only public information, then it cannot be decently called "encryption". Commented Mar 23, 2016 at 16:42
  • In fact, all these flawed explanations come from that weird habit of calling "encryption" the modular exponentiation that is done at the core of RSA. Of course, if you decide that any modular exponentiation is "encryption", then you will encrypt a lot of things. But that's, in practice, just plain confusing. Commented Mar 23, 2016 at 16:43
1

Private and Public keys can be used interchangeably to encrypt. That's the point. There is no (major) difference in the algorithm, but in the purpose of the keys.

By keeping the private key private, you have the sole, secret mechanism to decrypt messages from the public key. This ensures that only you can read the message.

By keeping the public key public, the world can decrypt messages from your private key. This process is not to keep the message secret, but to allow the world to be able to verify that you, and only you, encrypted the message.

9
  • Thank you. Why there are public and private keys is clear. I was wondering about the capacity (and drawbacks) to encrypt with one or the other - which is the first sentence of your answer.
    – WoJ
    Commented Mar 23, 2016 at 16:34
  • You are mixing encryption and authentication.
    – ferit
    Commented Mar 23, 2016 at 21:21
  • "but to allow the world to be able to verify that you, and only you, encrypted the message" what you describe here is authentication.
    – ferit
    Commented Mar 23, 2016 at 22:24
  • @schroeder And signing is about authentication.
    – ferit
    Commented Mar 23, 2016 at 22:35
  • @schroeder Why?
    – ferit
    Commented Mar 23, 2016 at 22:50
1

One interesting difference:

In case of RSA you can derive the public key from the private key but of course not vice versa.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .