Skip to content

Commit

Permalink
symmetric encryption fixed (#1542)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Călina Cenan <[email protected]>
  • Loading branch information
jeugregg and calina-c authored Jun 6, 2024
1 parent ba5e9ce commit 0062545
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ocean_lib/ocean/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions ocean_lib/ocean/test/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0062545

Please sign in to comment.