There’s a server, a client, and a hacker in a network. For encryption, the client and the server need to share their private keys. Wouldn’t the hacker be able to grab those during their transmission and decrypt further messages as they please?

  • RegalPotoo@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    5 months ago

    You’ve missed a key detail in how asymmetric encryption works:

    • For asymmetric encryption algorithms, you essentially have two keys - a “private” key, and a “public” key
    • If you know the private key it is trivial to calculate the public key, but the reverse isn’t true - just given the public key, it is essentially impossible to calculate the private key in a reasonable amount of time
    • If you encrypt something with the public key you must use the private key to decrypt it, and if you encrypt with the private key you can only use the public key for decryption
    • This means that my server can advertise a public key, and you can use that to encrypt the traffic so that only the server that knows the private key can decrypt it
    • Scubus@sh.itjust.works
      link
      fedilink
      arrow-up
      0
      ·
      5 months ago

      But how does the encryption work if you have the public key? Since your computer knows how to encrypt the data with the public key, couldn’t you use that same public key to run that algorithm in reverse? If not, since the public and private keys are not the same, how does the private key go about decrypting that data?

      • RegalPotoo@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        5 months ago

        The actual math is way beyond me, but the algorithm is “one way” - it exploits the fact that given two prime numbers (ie, the private key) it is trivial to multiply them together, but if you only know the result (ie, the public key) it is computationally very expensive to determine the original prime factors. If you pick big enough numbers, it becomes effectively impossible to undo the multiplication

  • slazer2au@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    5 months ago

    Why are they sharing private keys?

    The point of the system is you share public key so others can encrypt data and the you use your private key do decrypt it.

  • CyberSeeker@discuss.tchncs.de
    link
    fedilink
    arrow-up
    1
    ·
    5 months ago

    For encryption, the client and server need to share their private keys.

    This is incorrect, for asymmetric (public-private) encryption. You never, ever share the private key, hence the name.

    The private key is only used on your system for local decryption (someone sent a message encrypted with your public key) or for digital signature (you sign a document with your private key, which can be validated by anyone with your public key).

    For the server, they are signing their handshake request with a certificate issued by a known certificate authority (aka, CA, a trusted third party). This prevents a man-in-the-middle attack, as long as you trust the CA.

    The current gap is in inconsistent implementation of Organization Validation/Extended Validation (OV/EV), where an issuer will first validate that domains are legitimate for a registered business. This is to help prevent phishing domains, who will be operating with TLS, but on a near-name match domain (www.app1e.com or www.apple.zip instead of www.apple.com). Even this isn’t perfect, as business names are typically only unique within the country/province/state that issues the business license, or needed to be enforced by trademark, so at the end of the day, you still need to put some trust in the CA.

  • kevincox@lemmy.ml
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    5 months ago

    Great question. Modern encryption schemes are usually composed of a handful of primitives. If we consider something like HTTPS it uses both asymmetric and symmetric parts.

    Asymmetric encryption is the “magic” that you are missing. Asymmetric encryption algorithms create a keypair, one half of this is the “public key” which can be used to encrypt messages that can only be decrypted by the “private key”. This means that even if the public key is public (as the name suggests) the messages can’t be decrypted without the private key.

    You can think of this as giving someone an open padlock. They can put something inside a box and lock it using the padlock, but they can’t open it without your key.

    Using this you could come up with a very simple protocol for establishing a secure channel:

    1. The server sends you their public key, along with a certificate that proves that it belongs to them.
    2. The client then uses this public key to encrypt a key for symmetric encryption.
    3. The client sends this encrypted key to the server.
    4. The server decrypts the key.
    5. Now the client and server can both use the shared key to communicate.

    (Note: There are many missing features from this system, but I think it illustrates the point. Don’t design your own crypto.)

  • Sagar Acharya@sopuli.xyz
    link
    fedilink
    arrow-up
    0
    arrow-down
    1
    ·
    5 months ago

    Certifying Authority ensures secure connection establishment. If CA is corrupt, your system will work.