mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-22 16:44:27 +01:00
Adds blob encryption on both sides
This commit is contained in:
23
pisa-btc/pisa/encrypted_blob.py
Normal file
23
pisa-btc/pisa/encrypted_blob.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import hashlib
|
||||
from binascii import unhexlify
|
||||
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
||||
|
||||
|
||||
class EncryptedBlob:
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
|
||||
def decrypt(self, key):
|
||||
# Extend the key using SHA256 as a KDF
|
||||
extended_key = hashlib.sha256(key).digest()
|
||||
|
||||
# The 16 MSB of the extended key will serve as the AES GCM 128 secret key. The 16 LSB will serve as the IV.
|
||||
sk = extended_key[:16]
|
||||
nonce = extended_key[16:]
|
||||
|
||||
# Decrypt
|
||||
aesgcm = AESGCM(sk)
|
||||
data = unhexlify(self.data.encode)
|
||||
raw_tx = aesgcm.decrypt(nonce=nonce, data=data, associated_data=None)
|
||||
|
||||
return raw_tx
|
||||
Reference in New Issue
Block a user