-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncryption.py
More file actions
32 lines (29 loc) · 890 Bytes
/
Copy pathEncryption.py
File metadata and controls
32 lines (29 loc) · 890 Bytes
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
from Crypto.Cipher import AES
import hashlib
import base64
BLOCK_SIZE = 32
"""
Use this file to encrypt a password manually
"""
def decrypt(ciphertext, mode=AES.MODE_ECB):
key = "ueVbH0RGVHfLBo81/3BqHQ=="
key = base64.b64decode(key)
ciphertext = ciphertext.decode("hex")
encryptor = AES.new(key,mode)
plaintext = encryptor.decrypt(ciphertext)
plaintext = pkcs5_unpad(plaintext)
h = hashlib.new('sha1')
h.update(plaintext)
return h.hexdigest()
def encrypt(plaintext, mode=AES.MODE_ECB):
key = "ueVbH0RGVHfLBo81/3BqHQ=="
key = base64.b64decode(key)
cipher = AES.new(key, mode)
crypted = cipher.encrypt(pkcs5_pad(plaintext))
crypted = crypted.encode("hex")
return crypted
def pkcs5_unpad(s):
return s[0:-ord(s[-1])]
def pkcs5_pad(s):
return s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)
print(encrypt(raw_input("Enter plaintext: ")))