将 .pfx 证书附加到 exe 文件

发布于 2024-12-27 19:38:17 字数 244 浏览 7 评论 0原文

我必须将一个软件部署到 n 个客户端来安装证书并使用它。我不想部署两个文件(.pfx 和 exe),而只部署一个文件(.exe 将包含 .pfx)。

我现在正在做的是从某个位置导入证书。

X509Certificate2^ x509 = gcnew X509Certificate2;
x509->Import( "C:\\Tmp\\certficate.pfx" );

是否可以 ?

I have to deploy a software to n clients that will install a certificate and use it. I don't want to deploy two files (.pfx and exe) just one (.exe that will contain the .pfx).

What i'm doing now is import the certificate from a location.

X509Certificate2^ x509 = gcnew X509Certificate2;
x509->Import( "C:\\Tmp\\certficate.pfx" );

Is it possible ?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

探春 2025-01-03 19:38:17

您始终可以将证书数据作为资源嵌入。

但有一个警告:如果有人获得了可执行文件,他们就可以很容易地提取出 PFX 文件。

您能够安全地分发可执行文件吗?

以下是一些粗略步骤,摘自: http://www.spikezilla-software.com /blog/?p=24

  • 将 PFX 添加到您的项目中。然后单击该文件一次,在“属性”窗口中,将“构建操作”设置为“嵌入资源”
  • 读取嵌入的 PFX 文件并导入证书

这是 C#,但您应该能够非常轻松地转换为 C++/CLI:

var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyFile.pfx");
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
var cert = new X509Certificate2(bytes, "certPassword");

You could always embed the certificate data as a resource.

One warning though: if someone gets the executable, they can pull out the PFX file pretty easily.

Are you able to securely distribute the executable?

Here are some rough steps, distilled from: http://www.spikezilla-software.com/blog/?p=24

  • Add the PFX to your project. Then click once on the file, and in the Properties window, set the Build Action to Embedded Resource
  • Read the embedded PFX file and import the certificate

This is C# but you should be able to translate to C++/CLI pretty easily:

var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyFile.pfx");
var bytes = new byte[stream.Length];
stream.Read(bytes, 0, bytes.Length);
var cert = new X509Certificate2(bytes, "certPassword");
末が日狂欢 2025-01-03 19:38:17

一旦我嵌入它,这对我有用。

byte[] cert = Properties.Resources.nameOfCertificate;
X509Certificate2 x509 = new X509Certificate2();
x509.Import(cert, "password", X509KeyStorageFlags.MachineKeySet);

This worked for me once I embedded it.

byte[] cert = Properties.Resources.nameOfCertificate;
X509Certificate2 x509 = new X509Certificate2();
x509.Import(cert, "password", X509KeyStorageFlags.MachineKeySet);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文