Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating an RSA Key Pair with Erlang?

Erlang has a crypto function which generates public private keys (documentation copied below). However the documentation seems vague and I can't find any example code that describes how to generate the shared prime number or the generator. Can someone post an example that generates a public/private key pair? Thanks in advance for any 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 shared prime number and G is the shared generator. PublicKey, PrivateKey = Mpint() Generates a Diffie-Hellman PublicKey and PrivateKey (if not given).

like image 484
Nuvious Avatar asked Jan 20 '10 17:01

Nuvious


People also ask

How is RSA key pair generated?

You can generate RSA key pairs in the encrypted form on a workstation with a 4755 cryptographic adapter or a 4764 PCIX Cryptographic Coprocessor installed. A workstation with a 4758 PCI Cryptographic Coprocessor can also be used.

What is RSA key generator?

Description. RSA is an asymmetric encryption algorithm. With a given key pair, data that is encrypted with one key can only be decrypted by the other. This is useful for encrypting data between a large number of parties; only one key pair per person need exist.


2 Answers

You don't generate the shared prime number or the generator for Diffie-Hellman. See:

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

The parameters P and G are agreed to ahead of time by both sides. Using the notation of the Wikipedia article, crypto:dh_generate_key is used for steps 2 & 3 to generate a/A & b/B, and then crypto:dh_compute_key is used for steps 4 & 5 to compute the shared secret s.

For RSA, I don't know of a standard library function that generates a public/private key pair. Generating primes is a fairly involved algorithm from what I remember; I would strongly recommend you not try to code it yourself. Diffie-Hellman key pairs are not suitable for use with RSA; they are different algorithms intended for different purposes.

Generally you don't need to generate these at runtime since you can reuse the key pair. You can use any number of other sources to actually generate it. (Maybe ssh-keygen would work? And there's always OpenSSL.) To use the key pair you've created, you'd use the crypto:rsa_ public/private _ encrypt/decrypt functions.

like image 142
Tadmas Avatar answered Oct 12 '22 08:10

Tadmas


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

"cutkey is an Erlang app for generating RSA keys. It is implemented as a port driver that calls OpenSSL's RSA_generate_key on a thread from the async pool."

like image 25
goertzenator Avatar answered Oct 12 '22 07:10

goertzenator