如何让 SignerSignEx2 使用机器密钥库而不是用户密钥库?

How can I make SignerSignEx2 use the machine key store instead of the user one?

我目前正在尝试使用 SignerSignEx2 函数通过 Authenticode 对 DLL 进行签名。为此,我创建了一个私钥并将其放入机器密钥库(因此文件将存储在 C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys)。

不幸的是,SignerSignEx2 函数似乎只在用户存储中查找密钥(当我将密钥放入用户存储时(以便文件存储在 C:\Users{user} \AppData\Roaming\Microsoft\Crypto\RSA{user-id}) 它工作正常)。

有谁知道以使用机器密钥存储而不是用户存储的方式调用 SignerSignEx2 的方法吗?

本质上,功能应该类似于 CspParameters class,它允许使用 CspProviderFlags.UseMachineKeyStore 来控制使用哪个密钥库。

我相信您在打开证书存储区时需要 CERT_SYSTEM_STORE_LOCAL_MACHINE 标志才能获得所需内容。