Python:hashlib
MD5
Single file:
Multiple files:
SHA256
import hashlib
hash_object = hashlib.sha256(b'Hello World')
hex_dig = hash_object.hexdigest()
print(hex_dig)
pbkdf2_hmac
함수 정의:
# -*- coding: utf-8 -*-
from hashlib import pbkdf2_hmac
from typing import Final
DEFAULT_PBKDF2_HMAC_HASH_NAME: Final[str] = "sha256"
DEFAULT_PBKDF2_HMAC_ITERATIONS: Final[int] = 100000
def encrypt_password(password: str, salt: bytes) -> bytes:
return pbkdf2_hmac(
DEFAULT_PBKDF2_HMAC_HASH_NAME,
bytes.fromhex(password),
salt,
DEFAULT_PBKDF2_HMAC_ITERATIONS,
)
사용:
Using OpenSSL Algorithms
import hashlib
hash_object = hashlib.new('DSA')
hash_object.update(b'Hello World')
print(hash_object.hexdigest())
Favorite site
- hashlib — Secure hashes and message digests
- Hashing Strings with Python 1
- Sha256 Hash Dictionary attack Assignment with Python
References
-
Hashing_Strings_with_Python-Python_Central.pdf ↩