회원 로그인
|
암호화 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개(1/15페이지)
번호 | 제목 | 글쓴이 | 조회 | 날짜 |
---|---|---|---|---|
285 | [Python] 동적 import - 모듈을 변수로 받아오기 | 푸딩뱃살 | 405 | 2022.10.27 10:45 |
284 | [Python] 파이썬 3.7.7과 3.9.7의 os.path.expanduser() 차이 | 푸딩뱃살 | 440 | 2022.08.18 12:22 |
283 | [Python] error: Microsoft Visual C++ 9.0 is required. | 푸딩뱃살 | 659 | 2022.08.03 13:35 |
282 | [Python] pyscript | 푸딩뱃살 | 434 | 2022.06.09 11:21 |
281 | [Python] float is / float not is | 푸딩뱃살 | 583 | 2022.03.02 15:03 |
280 | [Python] 이터널 문자열 f | 푸딩뱃살 | 811 | 2022.01.27 16:35 |
279 | [Python] is와 ==의 차이 | 푸딩뱃살 | 475 | 2021.11.25 15:54 |
278 |
[Python] Error: ImportError: file |
푸딩뱃살 | 891 | 2021.11.16 11:24 |
277 | [Python] 파이썬 디컴파일 - uncompyle6 | 푸딩뱃살 | 750 | 2021.11.10 14:46 |
276 | [Python] 파이썬 확장자 설명 | 푸딩뱃살 | 538 | 2021.11.03 14:38 |
275 | [참고] 웹 fbx 뷰어 | 푸딩뱃살 | 456 | 2021.10.19 15:46 |
274 | [Python] enumerate() | 푸딩뱃살 | 487 | 2021.10.13 14:44 |
273 | [Python] 아나콘다에서 가상 환경 | 푸딩뱃살 | 696 | 2020.11.21 00:26 |
272 | [Python] pip로 설치 때 퍼미션 에러 | 푸딩뱃살 | 1247 | 2020.06.06 17:13 |
271 | [Python] OpenCV 10-3. 이미지 Thresholding - Otsu's Binarizatio | 푸딩뱃살 | 657 | 2020.06.05 14:01 |
270 | [Python] OpenCV 10-2. 이미지 Thresholding - Adaptive Threshold | 푸딩뱃살 | 678 | 2020.06.05 13:58 |
269 | [Python] OpenCV 10-1. 이미지 Thresholding | 푸딩뱃살 | 569 | 2020.06.05 13:56 |
268 | [Python] OpenCV 9-2. 색 추적 | 푸딩뱃살 | 745 | 2020.06.02 23:29 |
267 | [Python] OpenCV 9-1. 색공간 바꾸기 | 푸딩뱃살 | 630 | 2020.06.02 23:27 |
266 | [Python] OpenCV 8-3. 이미지 비트 연산 | 푸딩뱃살 | 512 | 2020.06.02 23:21 |