Re: MS CA and custom policy module (VB6)

From: morfy (morfy_at_NOROUTE.com)
Date: 09/05/03


Date: Fri, 5 Sep 2003 23:37:55 +0300


Hi and thanks for the answer.

I solved the case myself by understanding what was done in the c++ code and
made the same with vb (i could have used CAPICOM, just didn't recall that it
had that utilities class)

anyways i cut'n'paste how i solved my case for others who might ask the same
thing (notice this is not the full code ex. declarations are missing)

    ' constants defined in wincrypt.h
    lKeyUsage = (CERT_DIGITAL_SIGNATURE_KEY_USAGE Or _
    CERT_NON_REPUDIATION_KEY_USAGE Or CERT_DATA_ENCIPHERMENT_KEY_USAGE)

    ' i have omitted the c++ examples BYTE array[1] = 0;
    ' as far as i know, vb strings are internally bstr so i can forget the
ending chr(0) ?
    sKeyUsage = Chr(lKeyUsage)
    lKeyUsageLen = LenB(sKeyUsage) * 8

    Set oASN = New CCertEncodeBitString
    sEncoded = oASN.Encode(lKeyUsageLen, sKeyUsage)
    oCertSrv.SetCertificateExtension szOID_KEY_USAGE, _
                                     PROPTYPE_BINARY, _
                                     EXTENSION_CRITICAL_FLAG, _
                                     sEncoded

My problem was first that i didn't understood that the string the method
wants was a bitmask. i first understood that bitString meant the binary
presentattion of the 'value' (like 00101101).

Thanks, Antti

"Vishal Agarwal[MSFT]" <vishala@online.microsoft.com> wrote in message
news:Ok2a290cDHA.4020@tk2msftngp13.phx.gbl...
> Can you use CAPICOM ?
>
> If so, you can code something like:
> keyusage(0) = &H1
>
> keyusage(1) = &HF0
>
> encodeObj = New CERTENCODELib.CCertEncodeBitString()
>
> capicomObj = New CAPICOM.Utilities()
>
> keyusagestring = capicomObj.ByteArrayToBinaryString(keyusage)
>
> encodedstring = encodeObj.Encode(16, keyusagestring)
>
>
> Thanks,
> Vishal[MSFT]
> --
> This posting is provided "AS IS" with no warranties, and confers no rights