File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments