회원 로그인
|
암호화 ASE
암호화 ASE
:Python 3.4
참고)
http://blog.dokenzy.com
http://www.imcore.net/encrypt-decrypt-aes256-c-objective-ios-iphone-ipad-php-java-android-perl-javascript/
http://stackoverflow.com/questions/12562021/aes-decryption-padding-with-pkcs5-python
http://stackoverflow.com/questions/12524994/encrypt-decrypt-using-pycrypto-aes-256
http://www.di-mgt.com.au/cryptopad.html
https://github.com/dlitz/pycrypto
:Python 3.4
#-*- coding: utf-8 -*- import base64 import hashlib from Crypto import Random from Crypto.Cipher import AES BS = 16 pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS).encode() unpad = lambda s: s[:-ord(s[len(s)-1:])] def iv(): """ The initialization vector to use for encryption or decryption. It is ignored for MODE_ECB and MODE_CTR. """ return chr(0) * 16 class AESCipher(object): """ https://github.com/dlitz/pycrypto """ def __init__(self, key): self.key = key #self.key = hashlib.sha256(key.encode()).digest() def encrypt(self, message): """ It is assumed that you use Python 3.0+ , so plaintext's type must be str type(== unicode). """ message = message.encode() raw = pad(message) cipher = AES.new(self.key, AES.MODE_CBC, iv()) enc = cipher.encrypt(raw) return base64.b64encode(enc).decode('utf-8') def decrypt(self, enc): enc = base64.b64decode(enc) cipher = AES.new(self.key, AES.MODE_CBC, iv()) dec = cipher.decrypt(enc) return unpad(dec).decode('utf-8') key = 'abcdefghijklmnopqrstuvwxyz123456' message = '한글을 테스트 합니다.' _enc = 'gOXlygE+qxS+69zN5qC6eKJvMiEoDQtdoJb3zjT8f/E=' #message = 'imcore.net' #enc = 'kWyuTmUELRiREWIPpLy3ZA==' #message = 'Test English...' #answer = 'rvs4H8x4Q8sblGG1jkOHFQ==' enc = AESCipher(key).encrypt(message) dec = AESCipher(key).decrypt(_enc) print(_enc == enc) print(message == dec)
참고)
http://www.imcore.net/encrypt-decrypt-aes256-c-objective-ios-iphone-ipad-php-java-android-perl-javascript/
http://stackoverflow.com/questions/12562021/aes-decryption-padding-with-pkcs5-python
http://stackoverflow.com/questions/12524994/encrypt-decrypt-using-pycrypto-aes-256
http://www.di-mgt.com.au/cryptopad.html
https://github.com/dlitz/pycrypto
- aes.py (2KB) (0)
댓글 0개
| 엮인글 0개
285개(5/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
205 | [Python] Anaconda 사용 | 푸딩뱃살 | 3410 | 2017.08.28 17:51 |
204 | [Python] url 인코딩/디코딩 | 푸딩뱃살 | 6312 | 2017.08.12 19:23 |
203 | [Python] Qt5(ui) to py | 푸딩뱃살 | 2620 | 2017.07.04 15:29 |
202 | [VisualStudio] Visual Studio Community 2015 설치 파일 (다운로드) [1+1] | 푸딩뱃살 | 4496 | 2017.06.11 20:11 |
201 | [VisualStudio] Visual Studio Community 2015 삭제 | 푸딩뱃살 | 4270 | 2017.06.11 20:06 |
200 | [Python] PyQt4 to PyQt5 | 푸딩뱃살 | 2968 | 2017.06.02 16:50 |
199 | [Python] NumPy 라이브러리 설치 | 푸딩뱃살 | 3341 | 2017.05.18 15:14 |
198 | [Python] Python Decompiler | 푸딩뱃살 | 3933 | 2017.04.28 14:28 |
>> | [Python] 암호화 ASE | 푸딩뱃살 | 3426 | 2017.01.09 00:10 |
196 | [Python] 모듈 with xbox 360 controller | 푸딩뱃살 | 2096 | 2016.09.18 22:03 |
195 | [PHP] php 메모리 부족 (PHP Fatal error) | 푸딩뱃살 | 4299 | 2016.09.10 21:07 |
194 | [C#] 조건연산자 ?: | 푸딩뱃살 | 2937 | 2016.09.06 13:46 |
193 | [C#] object 형 변환 (with Unity) [1+1] | 푸딩뱃살 | 10529 | 2016.05.04 02:20 |
192 | [C#] 현재 시간 | 푸딩뱃살 | 3028 | 2016.02.28 23:23 |
191 | [C#] 문자열 Format | 푸딩뱃살 | 2461 | 2016.01.21 12:10 |
190 | [XML] XML 파싱 (with Unity) | 푸딩뱃살 | 7031 | 2016.01.20 10:33 |
189 | [PHP] PHP 전송 종류 | 푸딩뱃살 | 2402 | 2016.01.11 10:49 |
188 | [C#] 배열 | 푸딩뱃살 | 1199 | 2016.01.05 14:38 |
187 | [C#] 참조 ref, out (with Unity) | 푸딩뱃살 | 6068 | 2015.12.08 11:22 |
186 | [PHP] CodeIgniter(코드이그나이트) 사용 | 푸딩뱃살 | 11873 | 2015.12.06 17:46 |