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