Last active
December 24, 2015 01:49
-
-
Save nori3tsu/6726479 to your computer and use it in GitHub Desktop.
AES/ECB/PKCS5Padding
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
from Crypto.Cipher import AES | |
import base64 | |
BS = 16 | |
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS) | |
unpad = lambda s : s[0:-ord(s[-1])] | |
class AESCipher: | |
def __init__(self, key): | |
self.key = key | |
def encrypt(self, text): | |
cipher = AES.new(self.key, AES.MODE_ECB) | |
raw = pad(text) | |
enc = cipher.encrypt(raw) | |
return base64.b64encode(enc) | |
def decrypt(self, text): | |
cipher = AES.new(self.key, AES.MODE_ECB) | |
enc = base64.b64decode(text) | |
return unpad(cipher.decrypt(enc)) | |
if __name__== "__main__": | |
key="1234567890123456" | |
text = "nori3tsu" | |
cipher = AESCipher(key) | |
enctext = cipher.encrypt(text) | |
print "%s" % enctext | |
dectext = cipher.decrypt(enctext) | |
print "%s" % dectext |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mustafa Özcan
Kişisel Blog makalelerimi SEO konusundaki deneyimleri paylaştığım blogum.Fırsatları ayağınıza getiren mustafa ozcan blog kişisel temalı yazılar ile gündemde yer alan güncel yazıları sizlere sunma fırsatı ile.