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

hashlib 모듈 - blake2s 메서드(method)


/// 설명

RFC 7693 에 정의되어 있는 암호화 해시 함수입니다.

data: 해시를 적용할 메세지입니다.
digest_size: 해시함수를 통해 반환되는 해시의 크기를 지정합니다.
key: 해시함수에 적용할 비밀키입니다.
salt: 난수를 사용하여 해시를 생성합니다.
person: 다른 인자의 값이 같고, 해시의 목적이 다를 경우 사용합니다.(인자의 값이 같지 않아도 됩니다.)
fanout: 참고사이트
depth: 참고사이트
leaf_size: 참고사이트
node_offset: 참고사이트
node_depth: 참고사이트
inner_size: 함수 내부에서 사용되는 digest 크기
last_node: 참고사이트
usedforsecurity: 제한적인 상황에서 안전하지 않을 경우 False를 이용할 수 있습니다.

※ 형식
hashlib.blake2s(data=b'', *, digest_size=32, key=b'', salt=b'', person=b'', fanout=1, depth=1, leaf_size=0, node_offset=0, node_depth=0, inner_size=0, last_node=False, usedforsecurity=True)

reference
https://docs.python.org/3/library/hashlib.html#module-hashlib

/// 예제

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import os
from hashlib import blake2s
 
# RFC 7693
# digest_size     len(key)     len(salt)     len(person)
# 32              32           8             8
 
test_str = b'This is a string'
 
# Basic Hashing(Tree=sequential)
test = blake2s()
test.update(test_str)
print(test.hexdigest())  # 32d681fdba7f4260f8a0c7bf0a088878c3c4b1412af99392eb853f6af6ec6c17
 
# Keyed Hashing(Tree=sequential)
test = blake2s(key=b'use_your_key')
test.update(test_str)
print(test.hexdigest())  # 3fba40c0e4746390a67fb4096a010d43dfefb74df0914a014f1f673bb70020a6
 
# Randomized(salt) + Keyed Hashing(Tree=sequential)
salt = os.urandom(blake2s.SALT_SIZE)
test = blake2s(key=b'use_your_key', salt=salt)
test.update(test_str)
print(test.hexdigest())  # fb592e925276754bbe07ed990e4182b8bdd7b37793ea04ba06c5daaee403f3e6
 
# Keyed + Personalization Hashing(Tree=sequential)
test = blake2s(key=b'use_your_key', person=b'Task_1')
test.update(test_str)
print(test.hexdigest())  # 5ae392f4df173299842a2ad3eea84afc9b2a832fa0fdd612879d65ba7d2ffd00
 
# Keyed + Personalization Hashing
test = blake2s(key=b'use_your_key', person=b'Task_1',
               fanout=2)
test.update(test_str)
print(test.hexdigest())  # 70942acba8ea300b57651840012e142d8ecfd8a2b9c771748b36a41da24c640d
 
# Keyed + Personalization Hashing
test = blake2s(key=b'use_your_key', person=b'Task_1',
               fanout=2, depth=2)
test.update(test_str)
print(test.hexdigest())  # 947b76f9833e216fd0428cfa7c2b32b87a020e59f4d6571e8fe8ecc07799907f
 
# Keyed + Personalization Hashing
test = blake2s(key=b'use_your_key', person=b'Task_1',
               fanout=2, depth=2, leaf_size=1024)
test.update(test_str)
print(test.hexdigest())  # 3c439f6b8350fdb7810b1647282052b95382ab5e3022e6bf8dbc6d6da5c187ab
 
# Keyed + Personalization Hashing
test = blake2s(key=b'use_your_key', person=b'Task_1',
               fanout=2, depth=2, leaf_size=1024, inner_size=32)
test.update(test_str)
print(test.hexdigest())  # e49d34775aa204beffb9e3a52929e374412c6e437f334b23960f6e2fb6bb20ab
 
# Keyed + Personalization Hashing
test = blake2s(key=b'use_your_key', person=b'Task_1',
               fanout=2, depth=2, leaf_size=1024, inner_size=32, last_node=True)
test.update(test_str)
print(test.hexdigest())  # 8833729d98e44ff2ce94dc6f90b3a0462b13e3e1456a04cbf762e4d620735515
 
cs

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


– 당신을 응원합니다. –

댓글

이 블로그의 인기 게시물

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

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

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

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

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