Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """
- openssl genrsa -out example.com.rsa 1280
- dnssec-keyfromrsa example.com.rsa >Kexample.com.+008+33333.private
- """
- from subprocess import Popen,PIPE
- import sys,StringIO,re,base64
- # only these make sense with RSA keys
- dnssecalg={
- '1':'RSAMD5',
- '5':'RSASHA1',
- '8':'RSASHA256',
- '10':'RSASHA512',
- }
- tag=33333
- alg=8
- file=sys.argv[1]
- rsafile = open(file,'r')
- rsaparser=Popen(["openssl","rsa","-text"],stdin=rsafile,stdout=PIPE)
- (output,outerr)=rsaparser.communicate()
- # parse openssl RSA output into dict
- rsadict={}
- rsaitem=None
- for l in StringIO.StringIO(output):
- l = l.strip('\n\r')
- if l[0:5] == '-----':
- break
- m = re.match('^([A-Za-z0-9-]+):\s*(.*?)\s*$',l)
- if m:
- rsaitem=m.group(1).lower()
- rsaline=m.group(2)
- rsadict[rsaitem]=rsaline
- continue
- l = l.strip(' ')
- if rsaitem:
- rsadict[rsaitem] = rsadict[rsaitem]+l
- # show the dict in the desired format
- for k in ['Private-key-format','Algorithm','Modulus',
- 'PublicExponent','PrivateExponent','Prime1','Prime2',
- 'Exponent1','Exponent2','Coefficient']:
- if k == 'Private-key-format':
- v = 'v1.2'
- elif k == 'Algorithm':
- v = '%s (%s)'%(alg,dnssecalg[str(alg)])
- elif k == 'PublicExponent':
- v = 'AQAB'
- else:
- vhex=rsadict[k.lower()]
- v = base64.b64encode(re.sub('[:]','',vhex).decode('hex'))
- #print '<%s/%s>'%(vhex,v)
- print '%s: %s'%(k,v)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement