C#函数可以使用预填充参数运行OpenSSL X509证书生成命令,因此用户不需要与之互动?

发布于 2025-01-31 16:02:09 字数 1300 浏览 3 评论 0原文

我会使用一个C#函数,该函数将通过执行OpenSSL命令来生成X509证书。我找到了这篇文章:执行来自c#的多个命令提示符命令,这非常有用,所以我的功能看起来像这样的东西:

            Process cmd = new Process();

            cmd.StartInfo.FileName = "cmd.exe";
            cmd.StartInfo.RedirectStandardInput = true;
            cmd.StartInfo.UseShellExecute = false;

            cmd.Start();

            using (StreamWriter sw = cmd.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine("openssl genrsa -aes256 -out E:\\testing_folder\\test_file_com.key.pem 2048");
                    //other openssl commands
                }
            }

但是对我来说,我试图生成x509证书=>

  1. 首先,我正在将私钥生成一个文件privkey.key。
  2. 然后我执行openssl命令' req -new -new -sha256 -key privkey.key -out cert.csr.csr '以生成csr证书,和执行此操作时,会有一个提示要求您提供国家名称,州/省,密码等:
  3. < img src =“ https://i.sstatic.net/kgux9.png” alt =“ list item”>

所以我的问题是,是否可以使用预填充参数运行此命令需要与之互动吗?在我的c#函数中,我将如何编写这些提示的答案,并执行命令在不响应提示的情况下为提示提供答案的命令?

提前致谢!!

I wand to have a C# function that would generate x509 certificate by executing openssl commands. I found this post: Execute multiple command prompt commands from c#, which was very helpful,so my function will look like something like this:

            Process cmd = new Process();

            cmd.StartInfo.FileName = "cmd.exe";
            cmd.StartInfo.RedirectStandardInput = true;
            cmd.StartInfo.UseShellExecute = false;

            cmd.Start();

            using (StreamWriter sw = cmd.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine("openssl genrsa -aes256 -out E:\\testing_folder\\test_file_com.key.pem 2048");
                    //other openssl commands
                }
            }

but for me, I am trying to generate the x509 certificate =>

  1. First, I am generating private key as a file privkey.key
  2. Then I am executing the openssl command 'req -new -sha256 -key privkey.key -out cert.csr' to generate csr certificate, and when executing this, there is a prompt asking you for country name, state/province, password, etc.:
  3. List item

So my question is,Is it possible to run this command with a prefilled parameter so the user does not need to interact with it? in my C# function, how would I write answers to these prompts and execute the commands feeding the answers to the prompts without having the user respond to the prompts?

Thanks in advance!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文