Why do I get an exception "Invalid algorithm specified" in CEnroll2Class?

1

I want to implement CSR generation in C# for Windows XP SP3.

Added by assembly Interop.XENROLLLib

CSR Generation Code:

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);
}

If the HashAlgorithm property is not set, then the request is successfully generated and by default I get the SHA1 signature algorithm. But when setting any other algorithm, I get the exception:

"System.Runtime.InteropServices.COMException (0x80090008): Invalid algorithm specified. (Exception from HRESULT: 0x80090008)
   at XENROLLLib.CEnroll2Class.set_HashAlgorithm(String pbstr)"

I tested on two machines with Windows XP SP3. I also tried to specify HashAlgI instead of the algorithm name.

Here is a list of supported algorithms. enter image description here

Please, any tips from you.

c#
cryptography
windows-xp
com-interop
asked on Stack Overflow Jul 10, 2019 by Dmitriy

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0