파이썬[Python]: hashlib - pbkdf2_hmac 메서드

hashlib 모듈 - pbkdf2_hmac 메서드(method)


/// 설명

PKCS 시리즈(PKCS #5 v2.0) 중 하나로 패스워드를 이용하여 키를 생성하는 함수입니다. HMAC과 같은 유사난수 함수(pseudorandom function)를 적용하고 있습니다. 인자 dklen의 기본값은 사용하는 해시 함수의 digest_size 가 사용되어 집니다.

※ 형식
hashlib.pbkdf2_hmac(hash_name, password, salt, iterations)
hashlib.pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None)

/// 예제

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import os
import hashlib
 
test_name = 'sha256'
test_pass = b'password'
test_salt = os.urandom(16)  # bytes
test_iter = 100000  # iteration of algorithm
 
# producing a derived key
test_key = hashlib.pbkdf2_hmac(test_name, test_pass, test_salt, test_iter)
print(test_key)  # b"Q\xaa\xd8\xbd\xb2\x07\xab\xcf\xa72\x0c\xda\xdd\nw,\x89&'7\xe8P\xa9Q\x06\t\xae\xd4b\x19\xb8R"
print(test_key.hex())  # 51aad8bdb207abcfa7320cdadd0a772c89262737e850a9510609aed46219b852
 
test_key = hashlib.pbkdf2_hmac(test_name, test_pass, test_salt, test_iter, dklen=16)
print(test_key)  # b'\xec\xc5\x1b\x83l\xf5\xae\x8d\xc2u\xbd\x154\xe1\xf8\xf5'
print(test_key.hex())  # ecc51b836cf5ae8dc275bd1534e1f8f5
 
 
cs

* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

파이썬[Python]: 내장함수 - from_bytes 메서드

파이썬[Python]: 내장함수 - __len__ 메서드

파이썬[Python]: kivy - 한글 사용

파이썬[Python]: 내장함수 - bit_length 메서드

C 언어: sin 함수, cos 함수, tan 함수