Nov 04, 2014 The RSA Encryption Algorithm (2 of 2: Generating the Keys) Eddie Woo. Generate public private key online free. Understanding ECC through the Diffie-Hellman Key Exchange - Duration: 11:34. Fullstack Academy 38,452 views.
- Cryptography with Python Tutorial
- Useful Resources
- Selected Reading
In this chapter, we will focus on step wise implementation of RSA algorithm using Python.
Generating RSA keys
The following steps are involved in generating RSA keys −
- Create two large prime numbers namely p and q. The product of these numbers will be called n, where n= p*q
- Generate a random number which is relatively prime with (p-1) and (q-1). Let the number be called as e.
- Calculate the modular inverse of e. The calculated inverse will be called as d.
Algorithms for generating RSA keys
We need two primary algorithms for generating RSA keys using Python − Cryptomath module and Rabin Miller module.
Cryptomath Module
The source code of cryptomath module which follows all the basic implementation of RSA algorithm is as follows −
Algorithm Generate Private Key Rsa Key
RabinMiller Module
Private Key Bitcoin
The source code of RabinMiller module which follows all the basic implementation of RSA algorithm is as follows −
The complete code for generating RSA keys is as follows −
Output
Openssl Generate Rsa Key Pair
The public key and private keys are generated and saved in the respective files as shown in the following output.