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