I’ve been trying to get my head around this and I’ve watched a few videos but they don’t seem to specifically answer my question.

According to what I’ve found online, messages encrypted with a public key can only be decrypted with a private key. But in practice, how is that possible?

Surely a public key contains a set of instructions, and anyone could just run those instructions in reverse to decrypt a message? If everything you need to encrypt a message is stored within a public key, then how is it a one-way process?

It’s likely that I’m misunderstanding a core element of this!

  • GamingChairModel@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    7 months ago

    Look at the Diffie Helman scheme, with the example used in the Wikipedia page.

    • Alice and Bob agree in public, for everyone to see, that they’re gonna start with p=23 and g=5.
    • Alice has a secret key 4, and doesn’t tell anyone (not even Bob). She plugs her secret into the formula g^secret mod p, or 5^4 mod 23. 5^4 is 625, and dividing 625 into 23 gives a remainder of 4. So she tells Bob in public that she derived the number 4 from her secret.
    • Bob has a secret key of 3, does the same thing, and calculates 5^3 mod 23, which results in the number of 10, tells Alice.

    The magic of this scheme is that taking each side’s result and applying the same secret gets to the same final result. 10^4 mod 23 turns out to be the exact same number as 4^3 mod 23. So both sides get to the secret shared key 18, without disclosing that their secret numbers were 4 and 3, respectively.

    But if you try to drive the secret key from the information publicly exchanged, you’ll basically have to try each number until you get to the right one. It’s inefficient, and basically impossible to do once you’re using very large integers (300+ digits long).