Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cookie
committed
Jan 21, 2019
1 parent
129ca27
commit 39e5aec
Showing
14 changed files
with
152 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from Crypto.Cipher import AES | ||
from binascii import b2a_hex, a2b_hex | ||
|
||
|
||
class cryptoAES(object): | ||
def __init__(self, key): | ||
self.key = key[0:16] | ||
self.mode = AES.MODE_CBC | ||
self.ciphertext = None | ||
|
||
def encrypt(self, text): | ||
cryptor = AES.new(self.key, self.mode, self.key) | ||
length = 16 | ||
count = len(text) | ||
if count % length != 0: | ||
add = length - (count % length) | ||
else: | ||
add = 0 | ||
text = text + ('\0' * add) | ||
self.ciphertext = cryptor.encrypt(text) | ||
return bytes.decode(b2a_hex(self.ciphertext)) | ||
|
||
def decrypt(self, text): | ||
cryptor = AES.new(self.key, self.mode, self.key) | ||
plain_text = cryptor.decrypt(a2b_hex(text)) | ||
return bytes.decode(plain_text.rstrip(b'\0')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.