protected const string GpgExe = "gpg";
protected Process GetProcess(string arguments)
{
ProcessStartInfo info = new ProcessStartInfo
{
FileName = GpgExe,
Arguments = arguments,
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true
};
Process process = new Process { StartInfo = info };
return process;
}
public string GetVersion()
{
string version = "";
string arguments = "--version";
using (var process = this.GetProcess(arguments))
{
process.Start();
version = process.StandardOutput.ReadLine();
process.Close();
}
return version;
}
の代わりにこのような場合のために提供さGnuPG's unattended key generation capabilitiesを使用し、(GnuPGのの標準出力を解析し、続いて整合入力を提供することによって可能であるべきである)対話プロンプトに対してプログラムしよう。
リンクドキュメントページの構文を理解することはなく、簡単に紹介し、小さな例を提供します。
$ cat >foo <<EOF
%echo Generating a basic OpenPGP key
Key-Type: DSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: Joe Tester
Name-Comment: with stupid passphrase
Name-Email: [email protected]
Expire-Date: 0
Passphrase: abc
%pubring foo.pub
%secring foo.sec
# Do a commit here, so that we can later print "done" :-)
%commit
%echo done
EOF
$ gpg2 --batch --gen-key foo
[...]
$ gpg2 --no-default-keyring --secret-keyring ./foo.sec \
--keyring ./foo.pub --list-secret-keys
/home/wk/work/gnupg-stable/scratch/foo.sec
------------------------------------------
sec 1024D/915A878D 2000-03-09 Joe Tester (with stupid passphrase) <[email protected]>
ssb 1024g/8F70E2C0 2000-03-09