Created
July 6, 2018 08:07
-
-
Save agusmakmun/bb37ee37b1a549e5863d811df2878498 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import os | |
file = open("/home/agaust/rsa.txt") | |
key_start = re.compile("-----BEGIN RSA PRIVATE KEY-----") | |
key_end = re.compile("-----END RSA PRIVATE KEY-----") | |
def re_range(f, key_start, key_end) : | |
for line in f: | |
if key_start.match(line): | |
yield line | |
break | |
for line in f: | |
yield line | |
if key_end.match(line): | |
break | |
first_key = '' | |
for line in re_range(file, key_start, key_end): | |
first_key += line | |
dest = '/home/agaust/ssl' | |
if not os.path.exists(dest): | |
os.makedirs(dest) | |
if not os.path.exists(dest+'/rsa-new.txt'): | |
ssl_key = open('/home/agaust/rsa-new.txt', 'w') | |
ssl_key.write(first_key) | |
ssl_key.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment