Skip to content

Commit

Permalink
shared key to string
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartenVanDeKuilen committed Jun 5, 2024
1 parent eab7bb7 commit 8453d71
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*/_version.py
__pycache__
2 changes: 1 addition & 1 deletion unii/unii_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ async def send(
if self._writer is not None:
try:
with self._writer_lock:
self._writer.write(self._shared_key.encode('utf-8'))
self._writer.write(message.to_bytes(self._shared_key))
await self._writer.drain()
self.last_message_sent = datetime.now()
# logger.debug("Last message sent: %s", self.last_message_sent)
Expand Down
4 changes: 2 additions & 2 deletions unii/unii_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def to_bytes(self, shared_key: str | None = None) -> bytes:
# logger.debug("Initial value: 0x%s", initial_value.hex())

aes = AES.new(
shared_key, AES.MODE_CTR, initial_value=initial_value, nonce=b""
shared_key.encode(), AES.MODE_CTR, initial_value=initial_value, nonce=b""
)
payload = aes.encrypt(payload)
# logger.debug("Encrypted Payload: 0x%s", payload.hex())
Expand Down Expand Up @@ -405,6 +405,6 @@ def __init__(self, message: bytes, shared_key: str | None = None):
self.data = data

def _decrypt(self, shared_key: str, initial_value: bytes, payload: bytes):
aes = AES.new(shared_key, AES.MODE_CTR, initial_value=initial_value, nonce=b"")
aes = AES.new(shared_key.encode(), AES.MODE_CTR, initial_value=initial_value, nonce=b"")

return aes.decrypt(payload)

0 comments on commit 8453d71

Please sign in to comment.