openssl Commands

Generate
openssl dhparam -out public.key -5 1024
openssl genpkey -paramfile public.key -out privatekey.pem
openssl pkey -in privatekey.pem -pubout -out new_publickey.pem

openssl dhparam -in public.key -noout -C

openssl dhparam -in m_new_publickey.pem -in privatekey.pem -out shared.key -5 1024
openssl dgst -sha1 shared.key

e1d1acc4c850a9d656b69cb2c3dbce21fa798c4e
030f372cd4b1871fb9b79ae66694f8502f0ca56f
openssl genpkey -genparam -algorithm DH -pkeyopt dh_keygen_bits:1024 -out dhp.pem

openssl genpkey -genparam -algorithm DH -out dhp.pem

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:1024 -pkeyopt rsa_keygen_pubexp:5 -out priv.pem
openssl pkey -in priv.pem -text | less

generate private/public key keypair

openssl dhparam -out dhparam.pem -5 1024
openssl genpkey -paramfile dhparam.pem -out privatekey.pem

extract public key only

openssl pkey -in privatekey.pem -pubout -out publickey.pem

openssl pkey -pubin -in publickey.pem -text -noout


openssl genpkey -genparam -algorithm DH -out dhp.pem -pkeyopt dh_paramgen_generator:5
openssl pkeyparam -in dhp.pem -text
cat dhp.pem
openssl genpkey -paramfile dhp.pem -out dhkey1.pem -pkeyopt dh_paramgen_generator:5


openssl genpkey -paramfile dhp.pem -out dhkey_userA.pem
openssl pkey -in dhkey_userA.pem -text -noout
openssl genpkey -paramfile dhp.pem -out dhkey_userB.pem
openssl pkey -in dhkey_userB.pem -text -noout
openssl pkey -in dhkey_userA.pem -pubout -out dhpub_userA.pem
openssl pkey -pubin -in dhpub_userA.pem -text
openssl pkey -in dhkey_userB.pem -pubout -out dhpub_userB.pem

openssl pkey -pubin -in dhpub_userB.pem -text

openssl pkeyutl -derive -inkey dhkey_userA.pem -peerkey dhpub_userB.pem -out secret_userA.bin
openssl pkeyutl -derive -inkey dhkey_userB.pem -peerkey dhpub_userA.pem -out secret_userB.bin
cmp secret_userA.bin secret_userB.bin
openssl pkey -pubin -in secret_userB.bin -text

xxd secret_userA.bin

openssl dgst -sha1 secret_userA.bin

http://openssl.cs.utah.edu/docs/apps/genpkey.html
https://sandilands.info/sgordon/diffie-hellman-secret-key-exchange-with-openssl

Generate
openssl dhparam -out public.key -5 1024
openssl genpkey -paramfile public.key -out privatekey.pem
openssl pkey -in privatekey.pem -pubout -out new_publickey.pem

openssl dhparam -in public.key -noout -C

openssl dhparam -in m_new_publickey.pem -in privatekey.pem -out shared.key -5 1024
openssl dgst -sha1 shared.key

e1d1acc4c850a9d656b69cb2c3dbce21fa798c4e
030f372cd4b1871fb9b79ae66694f8502f0ca56f
openssl genpkey -genparam -algorithm DH -pkeyopt dh_keygen_bits:1024 -out dhp.pem

openssl genpkey -genparam -algorithm DH -out dhp.pem

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:1024 -pkeyopt rsa_keygen_pubexp:5 -out priv.pem
openssl pkey -in priv.pem -text | less

generate private/public key keypair

openssl dhparam -out dhparam.pem -5 1024
openssl genpkey -paramfile dhparam.pem -out privatekey.pem

extract public key only

openssl pkey -in privatekey.pem -pubout -out publickey.pem

openssl pkey -pubin -in publickey.pem -text -noout


openssl genpkey -genparam -algorithm DH -out dhp.pem -pkeyopt dh_paramgen_generator:5
openssl pkeyparam -in dhp.pem -text
cat dhp.pem
openssl genpkey -paramfile dhp.pem -out dhkey1.pem -pkeyopt dh_paramgen_generator:5


openssl genpkey -paramfile dhp.pem -out dhkey_userA.pem
openssl pkey -in dhkey_userA.pem -text -noout
openssl genpkey -paramfile dhp.pem -out dhkey_userB.pem
openssl pkey -in dhkey_userB.pem -text -noout
openssl pkey -in dhkey_userA.pem -pubout -out dhpub_userA.pem
openssl pkey -pubin -in dhpub_userA.pem -text
openssl pkey -in dhkey_userB.pem -pubout -out dhpub_userB.pem

openssl pkey -pubin -in dhpub_userB.pem -text

openssl pkeyutl -derive -inkey dhkey_userA.pem -peerkey dhpub_userB.pem -out secret_userA.bin
openssl pkeyutl -derive -inkey dhkey_userB.pem -peerkey dhpub_userA.pem -out secret_userB.bin
cmp secret_userA.bin secret_userB.bin
openssl pkey -pubin -in secret_userB.bin -text

xxd secret_userA.bin

openssl dgst -sha1 secret_userA.bin

http://openssl.cs.utah.edu/docs/apps/genpkey.html
https://sandilands.info/sgordon/diffie-hellman-secret-key-exchange-with-openssl