-
pyDes를 이용한 DES 암호화, 복호화Programing/Python 2014. 7. 25. 14:32
코드
#참고 #http://www.cppblog.com/AutomateProgram/archive/2013/01/06/197017.html import pyDes #http://twhiteman.netfirms.com/des.html import base64 class DES: def __init__(self, iv, key): self.iv = iv self.key = key def encrypt(self, data): k = pyDes.des(self.key, pyDes.ECB, self.iv, pad=None, padmode=pyDes.PAD_PKCS5) d = k.encrypt(data) d = base64.encodestring(d) return d def decrypt(self, data): k = pyDes.des(self.key, pyDes.ECB, self.iv, pad=None, padmode=pyDes.PAD_PKCS5) data = base64.decodestring(data) d = k.decrypt(data) return d if __name__ == '__main__': data = "Ya - Ha !" iv = '12345678' key = '12345678' des = DES(iv, key) encryptdata = des.encrypt(data.encode('utf-8')) print encryptdata decryptdata = des.decrypt(encryptdata) print decryptdata
결과
6Bvxaxzi1IPUglK4OFJAdA== Ya - Ha ! [Finished in 0.1s]
'Programing > Python' 카테고리의 다른 글
Python urllib2 예제 (0) 2012.06.19 Python MySQLdb 설치 및 에러 (0) 2012.04.25 Python Mysql Tutorial (0) 2012.04.16 Python SQLite Tutorial (0) 2012.04.16 requests 기본문법 (0) 2012.04.16