Added export key.

Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
HeshamTB 2020-04-18 15:23:06 +03:00
parent 45c1abd0fa
commit 0cb6d56236
Signed by: Hesham
GPG Key ID: 74876157D199B09E

12
rsa.py
View File

@ -75,6 +75,9 @@ def main():
if sys.argv[1] == "list":
listKeys()
if sys.argv[1] == "export": #rsa export <key>
key_file_name = sys.argv[2]
exportKey(key_file_name)
@ -205,7 +208,10 @@ def saveKeyFile(key, fileName):
os.makedirs(keysFolder)
with open(keysFolder+fileName, "w") as keyFile:
for entry in range(0, 6):
if key[entry] != 0:
keyFile.write(hex(key[entry])+"\n")
else:
pass
keyFile.write(key[ID]+"\n")
def printKey(key):
@ -238,6 +244,10 @@ def listKeys():
else: check = '\u2713'
print("{} {}\n".format(key[ID], check))
def exportKey(keyFileName):
key = readKeyFile(keyFileName)
public_key = (key[N], key[E],0,0,0,0,key[ID])
saveKeyFile(public_key, key[ID]+"-public")
print("Saved public form of key {}".format(key[ID]))
if __name__ == "__main__":
main()