-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption.py
More file actions
58 lines (42 loc) · 1.55 KB
/
encryption.py
File metadata and controls
58 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from Cryptodome.Cipher import AES
from Crypto.Util.Padding import pad
def encrypt(key,*info):
key = key.encode('utf-8')
print(info)
returnMsg = encryptInfo(info, key)
print (returnMsg)
def encryptInfo(infoList, key):
# Set up the AES encryption class
file1 = open("manager.bin", "a")
errorCheck = makeStr(infoList, key)
if errorCheck[0] == True:
file1.write(errorCheck[1])
file1.write('\n')
file1.close()
# Return status
return errorCheck[0]
def makeStr(infoList, key):
tempStr = ""
try:
for i in infoList:
# Set up the AES decryption cipher
encCipher = AES.new(key, AES.MODE_ECB)
# Convert the message to byte array
msgBytes = i.encode('utf-8')
# Pad and then encrypt
paddedMsg = pad(msgBytes, AES.block_size)
# AES requires plain/cipher text blocks to be 16 bytes
cipherText = encCipher.encrypt(paddedMsg)
# Add
print("The cipher text that was written to the file was: ", cipherText)
tempStr = tempStr + '|' + str(cipherText)
except Exception as e:
return [False,tempStr]
return [True, tempStr]
if __name__ == '__main__':
username = str(input("Please enter your username: "))
password = str(input("Please enter your password: "))
website = str(input("Please enter your website: "))
key = str(input("Please enter a key (Leave blank for default key): "))
print(len(key))
encrypt(key, username, password, website)