Skip to content

Commit

Permalink
remove Crypto.Cipher
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou authored Jan 18, 2024
1 parent 6d23f9d commit 4afac6c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions custom_components/localtuya/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from Crypto.Cipher import AES

from .common import pytuya

Expand All @@ -32,7 +31,9 @@ def decrypt(msg, key):
def _unpad(data):
return data[: -ord(data[len(data) - 1 :])]

return _unpad(AES.new(key, AES.MODE_ECB).decrypt(msg)).decode()
cipher = Cipher(algorithms.AES(key), modes.ECB(), default_backend())
decryptor = cipher.decryptor()
return _unpad(decryptor.update(msg) + decryptor.finalize()).decode()


def decrypt_udp(message):
Expand Down

0 comments on commit 4afac6c

Please sign in to comment.