How to generate Diffie-Hellman (DH) parameters using OpenSSL

Jorge GomesJorge Gomes
1 min read

Scenario:

For HAProxy, I want to use unique Diffie-Hellman parameters but you don’t know how to generate the .pem file using OpenSSL.

Solution:

Use this command to generate the parameters and save them in dhparams.pem:

generate-diffie-hellman-dh-parameters-using-openssl.txt 📋 Copy to clipboard⇓ Download

openssl dhparam -out dhparams.pem 4096

This command generates Diffie-Hellman parameters with 4096 bits. This provides good security while still providing a very reasonable performance for modern devices. Depending on your preferred level of Paranoia you might want to increase the number of bits even more.

Note that even for “only” 4096 bits generating the parameters will usually take a couple of minutes. Larger parameter sizes might take many hours to days to generate. Ensure that you are generating the parameters on a fast computer and not on your Raspberry Pi or similar!, even on my M2 took some minutes.

0
Subscribe to my newsletter

Read articles from Jorge Gomes directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Jorge Gomes
Jorge Gomes