I have been doing a lot of research on Diffie-Hellman, and I understand how Alice and Bob are able to get a shared g^ab using both of their private keys. However, I am unsure about how this can be applied to passwords (strings). I assume you have to do something with the hex version of both the password and g^ab, but what? Any help would be much appreciated!

  • 3
    $\begingroup$ What are you hoping to achieve by using "password strings" instead? Recall that all modern encryption/key agreement algorithms operate on plain binary data for a reason, trying to change that is generally not necessary/not beneficial. $\endgroup$
    – Luke Park
    Dec 16, 2019 at 19:49
  • $\begingroup$ A string can be thought of as a number in base 26 (or base 36 if you include digits). Use D-H to generate a shared number and convert that number to base 26. That can be treated as a string. $\endgroup$
    – rossum
    Dec 18, 2019 at 14:40

2 Answers 2


Strings are a special case of numbers. Everything computer algorithms operate on are just special cases of numbers. The string "abc" is commonly encoded as 0x616263, but that's just a number (6,382,179). A movie stored in an AVI file can be thought of as just one massive number, with potentially billions of digits. Numbers can be very large. That's not a problem. So there's no algorithmic problem with b being a number that happens to represent any string you like.

But you should never use Diffie-Hellman this way.

The first part of the confusion in your question is that Diffie-Hellman typically operates on random numbers. And human-selected passwords are not random in any useful way. So if you try to plug passwords into DH, you're on the wrong track.

The second part of the confusion is that the whole point of a key agreement protocol like DH is typically to agree on a ephemeral key, a key that will only be used for a short time and then thrown away. If you have some long-lived shared secret like a password, you typically wouldn't need a key agreement protocol. So DH is the wrong tool.


No, DH does not apply to strings. However, what you are likely trying to achieve is to perform Diffie-Hellman with authentication. For that you can use a PAKE protocol, which stands for Password Authenticated Key Exchange (Wikipedia obviously made a bit of a mess of the naming, Password-Authenticated Key Agreement would be PAKA, not PAKE).

In such protocols DH is performed and the password authentication is part of the protocol; if the password is not correct then either the protocol exits early or the shared secret is not computed to the correct value, which means that subsequent authentication will fail.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.