我想在Windows XP SP3的C#中实现CSR生成。
由程序集 Interop.XENROLLLib
添加CSR生成代码:
private string GenerateObsolete(string subject)
{
var certEnroll = new CEnroll2Class();
certEnroll.ProviderName = "Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)";
certEnroll.ProviderType = 24;
certEnroll.ContainerName = $"FGR-{Guid.NewGuid()}";
certEnroll.HashAlgorithm = "SHA-256";
//certEnroll.HashAlgID = 32780;
certEnroll.KeySpec = 1;
certEnroll.GenKeyFlags = 1;
return certEnroll.createRequest(XECR_CMC, subject, null);
}
如果未设置 HashAlgorithm 属性,则将成功生成请求,并且默认情况下,我将获得 SHA1 签名算法。但是在设置其他算法时,会出现异常:
"System.Runtime.InteropServices.COMException (0x80090008): Invalid algorithm specified. (Exception from HRESULT: 0x80090008)
at XENROLLLib.CEnroll2Class.set_HashAlgorithm(String pbstr)"
我在两台装有 Windows XP SP3 的计算机上进行了测试。我还尝试指定 HashAlgI 而不是算法名称。
请提供任何提示。