node-gpg is a Node.js wrapper that provides an interface to the GnuPG (GNU Privacy Guard) command-line utility, allowing JavaScript applications to perform cryptographic operations like encryption, decryption, signing, and verification. It was last published as version 0.2.0 in February 2020 and explicitly stated as 'work in progress' at that time. The project appears to be abandoned, with no activity since early 2020. It differentiates itself by offering a promise-based API, making it suitable for async/await patterns, unlike some older GPG wrappers. However, due to its inactivity, it may not be compatible with newer Node.js versions or GnuPG releases, and it lacks active maintenance or security updates.
npm install node-gpgVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `node-gpg` to encrypt a plaintext string for a specified recipient key and then decrypt it. This requires GnuPG to be installed and a key to be present in the keyring.
Consider using alternative, actively maintained GPG wrapper libraries or directly executing GPG commands via Node.js's `child_process` module, ensuring robust error handling.
Always use `const gpg = require('node-gpg');` for importing the module and its functions in Node.js environments.Ensure `gpg` is installed, accessible in the system's PATH, and that necessary keys are imported into the user's keyring. Test GPG functionality directly from the command line before troubleshooting `node-gpg`.
Thoroughly test `node-gpg` in your specific Node.js and GnuPG environment for critical use cases. For new projects, prioritize actively maintained alternatives to avoid future compatibility headaches.
Verify that the GPG key for the `recipientKeyId` you are using is correctly imported into your GnuPG keyring. You can list keys with `gpg --list-keys` and import them using `gpg --import <public_key_file>`.
Ensure the private key corresponding to the encrypted data's recipient is available in your GPG keyring. If the key is passphrase-protected, ensure GPG can prompt for or receive the passphrase. For automated systems, consider using `gpg-agent` or providing the passphrase securely.
Install GnuPG on your operating system if it's not already present. Verify that the `gpg` executable is reachable from your shell by typing `which gpg` (Linux/macOS) or `where gpg` (Windows). If not found, add its installation directory to your system's PATH environment variable.