x509certenroll

supply public key in CERTENROLL request


I want to request a cert (from AD cert server) using a template. I want to supply the public key in the request. Using msft's SDK sample

        IX509CertificateRequest iRequest = objEnroll.Request;

        // then get the inner PKCS10 request
        IX509CertificateRequest iInnerRequest = 
            iRequest.GetInnerRequest(InnerRequestLevel.LevelInnermost);
        IX509CertificateRequestPkcs10 iRequestPkcs10 = 
            iInnerRequest as IX509CertificateRequestPkcs10;

        // create CX500DistinguishedName
        CX500DistinguishedName objName = new CX500DistinguishedName();
        objName.Encode(subjectName, X500NameFlags.XCN_CERT_NAME_STR_NONE);

        // set up the subject name
        iRequestPkcs10.Subject = objName;

I think I then need to do some thing like this

         iRequestPkcs10.PublicKey.InitializeFromEncodedPublicKeyInfo(xx);

but I dont know what xx is. I have the public key (In a bouncy castle PKCS10 object), but what format must it be in to pass to this function?


Solution

  • You can specify the public key in a number of different formats.

    According to MSDN, InitializeFromEncodedPublicKeyInfo takes two parameters: the first is the public key, and the second is an EncodingType enumeration value that specifies the format of the public key you are supplying.