diff --git a/bitcoinlib/db.py b/bitcoinlib/db.py index 26bef1d2..8f26da69 100644 --- a/bitcoinlib/db.py +++ b/bitcoinlib/db.py @@ -159,12 +159,6 @@ class EncryptedBinary(TypeDecorator): cache_ok = True key, impl = _get_encryption_key(LargeBinary) - # if DATABASE_ENCRYPTION_ENABLED: - # if not DB_FIELD_ENCRYPTION_KEY: - # _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: - # key = bytes().fromhex(DB_FIELD_ENCRYPTION_KEY) def process_bind_param(self, value, dialect): if value is None or self.key is None or not (DB_FIELD_ENCRYPTION_KEY or DB_FIELD_ENCRYPTION_PASSWORD): @@ -182,16 +176,7 @@ class EncryptedString(TypeDecorator): FieldType for encrypted String storage using EAS encryption """ - # impl = String cache_ok = True - # key = None - # if DATABASE_ENCRYPTION_ENABLED: - # if not DB_FIELD_ENCRYPTION_KEY: - # _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 = LargeBinary - # key = bytes().fromhex(DB_FIELD_ENCRYPTION_KEY) key, impl = _get_encryption_key(String) def process_bind_param(self, value, dialect): @@ -204,6 +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:]) return aes_decrypt(value, self.key).decode('utf8') @@ -306,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(128), index=True, doc="Public or private WIF (Wallet Import Format) representation") + wif = Column(EncryptedString(260), 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,