My goal was to use gpg in node with child_process to verify a signature from database without passing the file but with the signature text, but when i try to pass the signature and the content to be verified it gives invalid signature, if i pass only the content to stdin and let the signature being the name of the file it works
Example code:
//spawn('gpg', ['--verify', 'signature.sig', '-']) solves the problem
const gpg = spawn('gpg', ['--verify', '-', '-'])
const signature = `-----BEGIN PGP SIGNATURE----- xxxx -----END PGP SIGNATURE-----`
const content = 'content'
gpg.stdin.write(signature)
gpg.stdin.write(content)
gpg.stdin.end()
gpg.stdout.on('data', (data) => {
console.log(`stdout: ${data}`)
})
gpg.stderr.on('data', (data) => {
console.error(`stderr: ${data}`)
})
gpg.on('close', (code) => {
console.log(`Finished with code ${code}`)
})
What i’ve already tried:
gpg.stdin.write(signature + "n" + content + "n")
gpg.stdin.write(signature + "n" + content")
gpg.stdin.write(content)
gpg.stdin.end(signature)
What results:
gpg: BAD signature from xxx
Silver Stitch is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.