(python2.7)
import random def generate_salt(digit_num): DIGITS_AND_ALPHABETS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" return "".join(random.sample(DIGITS_AND_ALPHABETS, digit_num)) salt = generate_salt(20) print(salt) # => 6FVWlstUjcGf7Dm48ekN
import hashlib salt = '6FVWlstUjcGf7Dm48ekN' digest = hashlib.sha256(salt + 'hoge').hexdigest() print(digest) # => fc7f81f346906c8633341ed5c5a4765ce0c9419b3e87529de199d287d0f4cab3