Cleanup:
- Interface exit codes - Clean up
This commit is contained in:
parent
611a6c45ea
commit
e5a66e4d29
0
__init__.py
Normal file
0
__init__.py
Normal file
@ -1,4 +1,4 @@
|
||||
|
||||
#!/usr/bin/python3
|
||||
|
||||
s = 'test message hello awdawd'
|
||||
print(s)
|
||||
|
15
rsa.py
15
rsa.py
@ -27,6 +27,7 @@ ID=6
|
||||
|
||||
def main():
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
if sys.argv[1] == "gen": ##rsa gen <keysize> <keyname>
|
||||
keyFileName = sys.argv[3]
|
||||
key = generateKeys(keyFileName, int(sys.argv[2]))
|
||||
@ -39,6 +40,7 @@ def main():
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
exit(1)
|
||||
exit(0)
|
||||
if sys.argv[1] == "encrypt": ##rsa encrypt <message> <key> <signer>
|
||||
if len(sys.argv) == 5:
|
||||
msg = sys.argv[2]
|
||||
@ -58,6 +60,7 @@ def main():
|
||||
print("Not enough arguments")
|
||||
print("rsa encrypt <message> <key> <signer>")
|
||||
#Make help function
|
||||
exit(0)
|
||||
if sys.argv[1] == "decrypt": ##rsa decrypt "<cipher>" <key>
|
||||
if len(sys.argv) == 4:
|
||||
cipher = sys.argv[2]
|
||||
@ -73,12 +76,17 @@ def main():
|
||||
else:
|
||||
print("Not enough arguments")
|
||||
print("rsa decrypt \"<cipher>\" <key>")
|
||||
exit(0)
|
||||
|
||||
if sys.argv[1] == "list":
|
||||
listKeys()
|
||||
exit(0)
|
||||
if sys.argv[1] == "export": #rsa export <key>
|
||||
key_file_name = sys.argv[2]
|
||||
exportKey(key_file_name)
|
||||
exit(0)
|
||||
#No command exit code
|
||||
exit(127)
|
||||
|
||||
|
||||
|
||||
@ -219,8 +227,9 @@ def printKey(key):
|
||||
n = key[N]
|
||||
e = key[E]
|
||||
d = key[D]
|
||||
id = key[ID]
|
||||
print("----------------------------------------------"+
|
||||
"\nID: {}".format(key[ID]) +
|
||||
"\nID: {}".format(id) +
|
||||
"\n{}-BIT KEY".format(n.bit_length())+
|
||||
"\nPUBLIC PART:"+
|
||||
"\n{0}/{1}".format(hex(n), hex(e))+
|
||||
@ -247,8 +256,8 @@ def listKeys():
|
||||
|
||||
def exportKey(keyFileName):
|
||||
key = readKeyFile(keyFileName)
|
||||
public_key = (key[N], key[E],0,0,0,0,key[ID])
|
||||
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]))
|
||||
print("Saved public form of key {} in keys folder".format(key[ID]))
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user