2

如何使用 c# 和命令行使用添加到当前密钥环的公钥加密文件?

谢谢。

4

4 回答 4

4

嗯,C#的充气城堡密码库可以用来加密和解密PGP;这是我们在内部用于 PGP 加密工作的。它是完全独立的,因此不依赖于现有的程序或库。

但是请记住,它是一个库而不是命令行程序。源代码附带了一些示例命令行程序实用程序,如果您需要使用 CLI,您可以构建它。

于 2009-07-31T18:12:08.647 回答
1

您可以使用gnupg-sharp,只要您可以使用 GPL 和 GnuPG。

于 2009-07-31T18:10:46.513 回答
1

SharpPrivacy - C# 的 OpenPGP

于 2009-07-31T18:12:09.787 回答
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;
        }
于 2009-08-01T19:36:48.253 回答