hbc-FIX94/pywii/pywii-tools/ecgenpriv.py

34 lines
584 B
Python
Raw Permalink Normal View History

2016-11-30 10:57:03 +01:00
#!/usr/bin/env python2
2016-11-23 06:35:12 +01:00
import sys, os
import pywii as wii
if len(sys.argv) != 2:
print "Usage: %s keyfile.priv"%sys.argv[0]
sys.exit(1)
print "Generating private key..."
k = wii.ec.gen_priv_key()
print "Private key:"
pk = k.encode('hex')
print "K =",pk[:30]
print " ",pk[30:]
print
print "Corresponding public key:"
q = wii.ec.priv_to_pub(k)
pq = q.encode('hex')
print "X =",pq[:30]
print " ",pq[30:60]
print "Y =",pq[60:90]
print " ",pq[90:]
fd = open(sys.argv[1],"wb")
os.fchmod(fd.fileno(), 0o600)
fd.write(k)
fd.close()
print "Saved private key to %s"%sys.argv[1]