From 00625455db6f9806278960dc727c6e9e12c3dc0c Mon Sep 17 00:00:00 2001 From: Gregory LANG Date: Thu, 6 Jun 2024 12:36:08 +0200 Subject: [PATCH] symmetric encryption fixed (#1542) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Călina Cenan --- ocean_lib/ocean/crypto.py | 4 ++-- ocean_lib/ocean/test/test_crypto.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ocean_lib/ocean/crypto.py b/ocean_lib/ocean/crypto.py index 8bf6f2e30..f45289c0b 100644 --- a/ocean_lib/ocean/crypto.py +++ b/ocean_lib/ocean/crypto.py @@ -18,8 +18,8 @@ def calc_symkey(base_str: str) -> str: """Compute a symmetric private key that's a function of the base_str""" base_b = base_str.encode("utf-8") # bytes - hash_b = sha256(base_b) - symkey_b = b64encode(str(hash_b).encode("ascii"))[:43] + b"=" # bytes + hash_b = sha256(base_b).hexdigest() + symkey_b = b64encode(hash_b.encode("ascii"))[:43] + b"=" # bytes symkey = symkey_b.decode("ascii") return symkey diff --git a/ocean_lib/ocean/test/test_crypto.py b/ocean_lib/ocean/test/test_crypto.py index cfc121041..a4b4533d7 100644 --- a/ocean_lib/ocean/test/test_crypto.py +++ b/ocean_lib/ocean/test/test_crypto.py @@ -12,6 +12,8 @@ def test_symkey(): base_str = "foo" symkey = crypto.calc_symkey(base_str) assert isinstance(symkey, str) + wrong_symkey = crypto.calc_symkey("testwrong") + assert wrong_symkey != symkey, "NOK : wrong_sym_key is the same as sym_key" @enforce_types