Creating RSA key pairs with Erlang?

Erlang has a crypto function that generates public private keys (documentation copied below). However, the documentation seems vague, and I cannot find any sample code that describes how to generate a common prime number or generator. Can someone post an example that generates a pair of public / private keys? Thanks in advance for your help!

dh_generate_key(DHParams) -> {PublicKey,PrivateKey} dh_generate_key(PrivateKey, DHParams) -> {PublicKey,PrivateKey} 

Types: DHParameters = [P, G] P, G = Mpint Where P is the total total, and G is the common generator. PublicKey, PrivateKey = Mpint () Creates a Diffie-Hellman PublicKey and PrivateKey (if not specified).

+6
erlang cryptography rsa public-key private-key
source share
3 answers

You are not generating a total number or generator for Diffie-Hellman. Cm:

http://en.wikipedia.org/wiki/Diffie-Hellman_key_exchange

Parameters P and G are agreed in advance by both parties. Using the notation of the Wikipedia article, crypto:dh_generate_key used for steps 2 and 3 to generate a / a and b / b , and then crypto:dh_compute_key used for steps 4 and 5 to calculate the shared secret s .

For RSA, I do not know the standard library function that generates a public / private key pair. Generating prime numbers is a pretty complicated algorithm from what I remember; I would strongly recommend that you not try to code it yourself. Diffie-Hellman keys are not suitable for use with RSA; these are different algorithms designed for different purposes.

Generally, you do not need to create them at run time, as you can reuse a key pair. You can use any number of other sources to generate it. (Maybe ssh-keygen will work? And always OpenSSL .) To use the generated key pair, you should use crypto:rsa_ public/private _ encrypt/decrypt .

+7
source share

See cutkey ( https://github.com/yrashk/cutkey )

"cutkey is an Erlang RSA key generation application. It is implemented as a port driver that calls OpenSSL RSA_generate_key in a stream from an asynchronous pool.

+2
source share

os: command ("openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits: 2048").

0
source share

All Articles