Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- android
- 계측
- tabbar
- Button
- intent
- Flutter
- textview
- Coroutines
- 앱바
- LifeCycle
- TEST
- scroll
- textfield
- viewmodel
- Compose
- data
- Navigation
- Dialog
- activity
- livedata
- appbar
- ScrollView
- drift
- binding
- 안드로이드
- 앱
- DART
- Kotlin
- CustomScrollView
- 테스트
Archives
- Today
- Total
Study Record
[암호 프로그래밍] HMAC , CMAC 프로그램 본문
728x90
HMAC - SHA256 사용하기
from Crypto.Hash import HMAC, SHA256
message = b'hello' # message
secretKey = b'secret' # key
hMac = HMAC.new(secretKey, message, digestmod=SHA256)
print(hMac.hexdigest())
HMAC - SHA256 유효성 검사
from Crypto.Hash import HMAC, SHA256
recMsg = b'hello'
recvMac = '88aab3ede8d3adf94d26ab90d3bafd4a2083070c3bcce9c014ee04a443847c0b'
secretKey = b'secret'
hMac = HMAC.new(secretKey, recMsg, SHA256)
# 내가 만든 HMAC 값과 받은 MAC 값을 확인해본다.
try:
hMac.hexverify(recvMac)
print("[ OK ] Authentic")
except Exception as e:
print("[ FAIL ] Not authentic")
CMAC 사용하기
from Crypto.Hash import CMAC
from Crypto.Cipher import AES
# sender
message = b'hello'
secretKey = b'sixteen byte Key'
# cmac create
cmac = CMAC.new(secretKey, ciphermod=AES)
cmac.update(message)
sendMsg = message
sendMac = cmac.digest()
# receiver
recvMsg = sendMsg
recvMac = sendMac
h = CMAC.new(secretKey, ciphermod=AES)
h.update(recvMsg)
# verify
try:
h.verify(recvMac)
print('[ OK ] Authentic ')
except Exception as e:
print('Error:', e)
print('Not authentic')
728x90
'암호 > 프로그래밍' 카테고리의 다른 글
[암호 프로그래밍] 하이브리드 암호 프로그램 (0) | 2021.12.10 |
---|---|
[암호 프로그래밍] 해시 함수 사용하기 (0) | 2021.12.10 |
[암호 프로그래밍] 해시 함수 관련 프로그램 (0) | 2021.12.09 |
[암호 프로그래밍] RSA를 이용한 암/복호화 , 서명 (0) | 2021.12.08 |
[암호 프로그래밍] 인코딩/디코딩 프로그램 (0) | 2021.12.07 |