I am struggling to change a GnuPG private key passphrase with a script.
This is as far as I get: it returns that the process was successful at the end, but it doesn't change the passphrase. Any other form of options to gpg result in errors and no passphrase change.
Anyone have any hints? I'll accept answers using Symfony's process component or without - I just need to get it working.
Python/Bash/Expect answers also welcome. It should work without exposing the passphrase in the command line.
use Symfony\Component\Process\InputStream;
use Symfony\Component\Process\Process;
$fingerprint = '0123456789ABCDEF';
$previous = 'secret';
$passphrase = 'moresecret';
$process = new Process(
[
'gpg',
'--passphrase-fd=0',
'--pinentry-mode=loopback',
'--change-passphrase',
$fingerprint,
]
);
$input = new InputStream();
$process->setInput($input);
$process->start();
$input->write($previous."\n");
$input->write($passphrase."\n");
$input->close();
foreach ($process as $type => $data) {
if ($process::OUT === $type) {
echo "\nSTDOUT: $data";
} else {
echo "\nSTDERR: $data";
}
}
return $process->isSuccessful();