Skip to content

Instantly share code, notes, and snippets.

@agusmakmun
Created July 6, 2018 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agusmakmun/bb37ee37b1a549e5863d811df2878498 to your computer and use it in GitHub Desktop.
Save agusmakmun/bb37ee37b1a549e5863d811df2878498 to your computer and use it in GitHub Desktop.
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