Files
python-teos/pisa-btc/pisa/encrypted_blob.py
2019-08-09 15:00:02 +01:00

24 lines
688 B
Python

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