/
githubmirror
/
edx-platform
Обзор
Документация
Войти
/
githubmirror
/
edx-platform
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
release-ulmo
openedx/core/lib/hash_utils.py
34 строки
1 KB
github-actions[bot]
feat: Upgrade Python dependency edx-enterprise (#36616)
28 апр 2025, 21:43
Не верифицирован
28 апр 2025, 21:43
7252348
Код
Авторство
О чём код?
""" Utilities related to hashing This duplicates functionality in django-oauth-provider, specifically long_token and short token functions which was used to create random tokens """ import hashlib from django.utils.encoding import force_bytes from django.utils.crypto import get_random_string from django.conf import settings def create_hash256(max_length=None): """ Generate a hash that can be used as an application secret Warning: this is not sufficiently secure for tasks like encryption Currently, this is just meant to create sufficiently random tokens """ hash_object = hashlib.sha256(force_bytes(get_random_string(32))) hash_object.update(force_bytes(settings.SECRET_KEY)) output_hash = hash_object.hexdigest() if max_length is not None and len(output_hash) > max_length: return output_hash[:max_length] return output_hash def short_token(): """ Generates a hash of length 32 Warning: this is not sufficiently secure for tasks like encription Currently, this is just meant to create sufficiently random tokens """ return create_hash256(max_length=32)