์•Œ๊ณ ๋ฆฌ์ฆ˜

[Data Structure] hash() ํ•ด์‹œ ํ•จ์ˆ˜

jjingle 2024. 1. 29. 11:12

SHA(Secure Hash Algorithm)

- ์•ˆ์ „ํ•œ ํ•ด์‹œ ์•Œ๊ณ ๋ฆฌ์ฆ˜
- ์–ด๋–ค ๋ฐ์ดํ„ฐ๋„ ์œ ์ผํ•œ ๊ณ ์ •๋œ ํฌ๊ธฐ์˜ ๊ณ ์ •๊ฐ’์„ ๋ฆฌํ„ด

 

 

SHA-1

import hashlib

data = 'test'.encode()
hash_object = hashlib.sha1()
hash_object.update(data)
hex_dig = hash_object.hexdigest()

print(hex_dig) #a94a8fe5ccb19ba61c4c0873d391e987982fbbd3

 

SHA-256

import hashlib

data = 'test'.encode()
hash_object = hashlib.sha256()
hash_object.update(data)
hex_dig = hash_object.hexdigest()

print (hex_dig) #9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08