Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
if a pre-derived key is supplied to FernetEncrypter, prefer that to p…
…assword/salt
  • Loading branch information
jschlyter committed Apr 27, 2022
commit 1723845a90a696424593d8d44bbf0b21022b8b7d
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exclude_lines = [

[tool.poetry]
name = "cryptojwt"
version = "1.8.1"
version = "1.8.2"
description = "Python implementation of JWT, JWE, JWS and JWK"
authors = ["Roland Hedberg <roland@catalogix.se>"]
license = "Apache-2.0"
Expand Down
14 changes: 7 additions & 7 deletions src/cryptojwt/jwe/fernet.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ def __init__(
):
Encrypter.__init__(self)

if password is not None:
if key is not None:
if not isinstance(key, bytes):
raise TypeError("Raw key must be bytes")
if len(key) != 32:
raise ValueError("Raw key must be 32 bytes")
self.key = base64.urlsafe_b64encode(key)
elif password is not None:
_alg = getattr(hashes, hash_alg)
# A bit special for SHAKE* and BLAKE* hashes
if hash_alg.startswith("SHAKE") or hash_alg.startswith("BLAKE"):
Expand All @@ -35,12 +41,6 @@ def __init__(
salt = as_bytes(salt) if salt else os.urandom(16)
kdf = PBKDF2HMAC(algorithm=_algorithm, length=32, salt=salt, iterations=iterations)
self.key = base64.urlsafe_b64encode(kdf.derive(as_bytes(password)))
elif key is not None:
if not isinstance(key, bytes):
raise TypeError("Raw key must be bytes")
if len(key) != 32:
raise ValueError("Raw key must be 32 bytes")
self.key = base64.urlsafe_b64encode(key)
else:
self.key = Fernet.generate_key()

Expand Down