Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symmetric encryption fixed #1542

Merged
merged 6 commits into from
Jun 6, 2024
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
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
Loading