c#とコマンドラインを使用して、現在のキーリングに追加された公開鍵でファイルを暗号化する方法は?
ありがとう。
さて、C#用の弾力のある城暗号化ライブラリを使用してPGPを暗号化および復号化できます。これは、PGP暗号化作業のために内部的に使用するものです。完全に自己完結型であるため、既存のプログラムやライブラリに依存することはありません。
ただし、これはコマンドラインプログラムではなくライブラリであることに注意してください。ソースコードには、CLIを使用する必要がある場合に構築できるコマンドラインプログラムユーティリティの例がいくつか付属しています。
GPLとGnuPGの使用に問題がない限り、gnupg-sharpを使用できます。
1 年前に書いた私の実装を使用できます。私はそれが少し醜いことを知っています。
pgp.exe とその背景が必要です。私のブログ投稿を参照してください。
/// <summary>
/// Encryps given file using PGP Public Key
/// </summary>
/// <param name="filename"></param>
public string Encrypt(string filename, bool isBinary, ref string outstr){
string outputfilename = filename;
//We use stringbuilder for performance considerations
StringBuilder sb = new StringBuilder();
sb.Append("/c ");
sb.Append("");
sb.Append(PGPLocation);
sb.Append(" +force -es ");
sb.Append("\"");
sb.Append(filename);
sb.Append("\" ");
sb.Append(ToUserName);
sb.Append(" -u ");
sb.Append(MyUserName);
sb.Append(" -z ");
sb.Append(PassPhrase);
sb.Append(" ");
// Use binary indicator because PGP produces different outputs for binary and plain text files
if (isBinary)
sb.Append("-a");
proc.StartInfo.Arguments = sb.ToString();
//proc.StartInfo.Arguments = "/c pgp +force -es "+filename+" cumacam -u bugra";
proc.Start();
if (WaitForInfinity)
proc.WaitForExit();
else
proc.WaitForExit(WaitTime);
//string res = proc.StandardOutput.ReadToEnd();
outstr = proc.StartInfo.Arguments;
if (proc.HasExited)
{
int ab = proc.ExitCode;
if (ab != 0)
{
FireError(Convert.ToInt32(ErrorTypes.PGPEncryptError), "Erro No: " + ab.ToString() + "in PGP. Details: "+" "+proc.StandardOutput.ReadToEnd());
return null;
}
else
if (!isBinary)
return outputfilename+".pgp";
return outputfilename + ".asc";
}
return null;
}