summaryrefslogtreecommitdiff
path: root/django/utils/crypto.py
diff options
context:
space:
mode:
authorMattBlack85 <promat85@gmail.com>2014-02-16 14:47:51 +0100
committerHonza Král <honza.kral@gmail.com>2014-02-16 16:50:50 +0100
commita8ba76c2d3ad95595590af31c5cda123dc3868b7 (patch)
treea4946df9c6c1ef13d49fe2b142141cba99b2278f /django/utils/crypto.py
parent8274fa60f88607eb0e81908f049c391455956dd8 (diff)
Fixed #19980: Signer broken for binary keys (with non-ASCII chars).
With this pull request, request #878 should considered closed. Thanks to nvie for the patch.
Diffstat (limited to 'django/utils/crypto.py')
-rw-r--r--django/utils/crypto.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/utils/crypto.py b/django/utils/crypto.py
index 963f9e01e8..21395fe8a3 100644
--- a/django/utils/crypto.py
+++ b/django/utils/crypto.py
@@ -36,10 +36,13 @@ def salted_hmac(key_salt, value, secret=None):
if secret is None:
secret = settings.SECRET_KEY
+ key_salt = force_bytes(key_salt)
+ secret = force_bytes(secret)
+
# We need to generate a derived key from our base key. We can do this by
# passing the key_salt and our base key through a pseudo-random function and
# SHA1 works nicely.
- key = hashlib.sha1((key_salt + secret).encode('utf-8')).digest()
+ key = hashlib.sha1(key_salt + secret).digest()
# If len(key_salt + secret) > sha_constructor().block_size, the above
# line is redundant and could be replaced by key = key_salt + secret, since