Skip to content

Commit

Permalink
Correctly store encrypted fields as bytes in psql database
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryp Toon committed Feb 24, 2024
1 parent a005eee commit 5905559
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions bitcoinlib/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,10 @@ def _get_encryption_key(default_impl):
_logger.warning("Database encryption is enabled but value DB_FIELD_ENCRYPTION_KEY not found in "
"environment. Please supply 32 bytes key as hexadecimal string.")
if DB_FIELD_ENCRYPTION_KEY:
impl = default_impl
impl = LargeBinary
key = bytes().fromhex(DB_FIELD_ENCRYPTION_KEY)
elif DB_FIELD_ENCRYPTION_PASSWORD:
impl = default_impl
impl = LargeBinary
key = double_sha256(bytes(DB_FIELD_ENCRYPTION_PASSWORD, 'utf8'))
return key, impl

Expand Down Expand Up @@ -189,8 +189,8 @@ def process_bind_param(self, value, dialect):
def process_result_value(self, value, dialect):
if value is None or self.key is None or not (DB_FIELD_ENCRYPTION_KEY or DB_FIELD_ENCRYPTION_PASSWORD):
return value
if value.startswith('\\x'):
value = bytes.fromhex(value[2:])
# if value.startswith('\\x'):
# value = bytes.fromhex(value[2:])
return aes_decrypt(value, self.key).decode('utf8')


Expand Down Expand Up @@ -293,7 +293,7 @@ class DbKey(Base):
address_index = Column(BigInteger, doc="Index of address in HD key structure address level")
public = Column(LargeBinary(65), index=True, doc="Bytes representation of public key")
private = Column(EncryptedBinary(48), doc="Bytes representation of private key")
wif = Column(EncryptedString(260), index=True, doc="Public or private WIF (Wallet Import Format) representation")
wif = Column(EncryptedString(128), index=True, doc="Public or private WIF (Wallet Import Format) representation")
compressed = Column(Boolean, default=True, doc="Is key compressed or not. Default is True")
key_type = Column(String(10), default='bip32', doc="Type of key: single, bip32 or multisig. Default is bip32")
address = Column(String(100), index=True,
Expand Down

0 comments on commit 5905559

Please sign in to comment.