Skip to content

Commit b661cf7

Browse files
Create rsa_key_generator.py
1 parent 790d83d commit b661cf7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rsa_key_generator.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import os # for handling paths and removing files (FTP mode)
5+
import sys # for getting sys.argv
6+
from Crypto.PublicKey import RSA
7+
import getpass # for securely entering a user's pass phrase to access the private key
8+
9+
# - GLOBAL SCOPE VARIABLES start -
10+
full_path = os.path.dirname(os.path.realpath(sys.argv[0]))
11+
# - GLOBAL SCOPE VARIABLES end -
12+
13+
# GENERATE NEW RSA PUBLIC-PRIVATE KEY PAIR:
14+
passphrase = getpass.getpass(prompt='Enter your private key passphrase')
15+
new_key = RSA.generate(4096)
16+
export_format = 'PEM'
17+
private_key = new_key.exportKey(pkcs=8, passphrase=passphrase)
18+
public_key = new_key.publickey().exportKey(format=export_format)
19+
with open(os.path.join(full_path, "private_key." + export_format.lower()), "wb") as f:
20+
f.write(private_key)
21+
with open(os.path.join(full_path, "public_key." + export_format.lower()), "wb") as f:
22+
f.write(public_key)

0 commit comments

Comments
 (0)