hbc/pywii/pywii-tools/ecpriv2pub.py

31 lines
593 B
Python
Raw Normal View History

2021-03-17 15:53:31 +01:00
#!/usr/bin/env python3
2016-11-23 06:35:12 +01:00
import sys
import pywii as wii
if len(sys.argv) not in (2,3):
2021-03-17 15:53:31 +01:00
print("Usage: %s keyfile.priv [keyfile.pub]"%sys.argv[0])
2016-11-23 06:35:12 +01:00
sys.exit(1)
if sys.argv[1] == "-":
k = sys.stdin.read()
else:
k = open(sys.argv[1],"rb").read()
if len(k) != 30:
2021-03-17 15:53:31 +01:00
print("Failed to read private key")
2016-11-23 06:35:12 +01:00
sys.exit(2)
2021-03-17 15:53:31 +01:00
print("Public key:")
2016-11-23 06:35:12 +01:00
q = wii.ec.priv_to_pub(k)
pq = q.encode('hex')
2021-03-17 15:53:31 +01:00
print("X =",pq[:30])
print(" ",pq[30:60])
print("Y =",pq[60:90])
print(" ",pq[90:])
2016-11-23 06:35:12 +01:00
if len(sys.argv) == 3:
fd = open(sys.argv[2],"wb")
fd.write(q)
fd.close()
2021-03-17 15:53:31 +01:00
print("Saved public key to %s"%sys.argv[2])