Home GnuPG

GPGME Python Binding Decryption Fails with "Bad passphrase" Despite Valid Key
ActivePublic

GPGME Python Binding Decryption Fails with "Bad passphrase" Despite Valid Key

While integrating GPGME’s Python bindings (v1.23.2) with a file encryption/decryption workflow on Ubuntu 22.04 (GnuPG 2.4.4, Python 3.11), I encountered a persistent Bad passphrase error during Slope Game decryption, despite the passphrase being valid and the same keypair working flawlessly via the GPG CLI. The workflow involves generating a new key with a passphrase, encrypting a text file programmatically using ctx.encrypt with ENCRYPT_ALWAYS_TRUST, and then attempting to decrypt it in a fresh context with a passphrase callback. The encryption completes without issue, but decryption fails every time, even when explicitly setting --pinentry-mode loopback in the context. I have verified that the passphrase callback is being invoked and returns the correct bytes, tried multiple approaches to ensure the context flags match those in the working CLI command, and confirmed that the error occurs on both new and existing keys. This leads me to suspect either a subtle bug in the passphrase handling logic of the Python bindings or an unexpected interaction with the underlying GPG agent configuration, as the exact same operations succeed when run directly through gpg --batch. Has anyone experienced similar behavior, or identified a workaround that preserves full automation without prompting?

Panel Used By

This panel is not used on any dashboard or inside any other panel container.