views:

135

answers:

2

Hello Experts, I have my certrequest as a PEM base64 data. See data below.

1) My understanding is that this is an ASCII data type and not in UNICODE format. Please clarify.

-----BEGIN NEW CERTIFICATE REQUEST----- MIIBTjCBuAIBADARMQ8wDQYDVQQDEwZ3dTAwMzEwgZ0wDQYJKoZIhvcNAQEBBQAD gYsAMIGHAoGBAKP48eljetv3fVicT6g6hKjmLpsySJaZ/NnepEJEqtQQNbwsluhW yWxhHWzPoNPV9uqjZBW7EnqYjxyPp1A0vOK35uxmmcNrgmuSjO1WBkD0YVZwzh2u OovRCOwJKklQtJnQWoM+yT8CyBVk7raVJOrLDMC8FR5AMknVCIlt7HppAgEDoAAw DQYJKoZIhvcNAQEFBQADgYEAAK5G10e39GxiNiPXdrOAwtuIiLd1UTWn3VYY7nYY 74LhydUBjo0Xi6HBTTNVlPNoRB9GOe5P1Qgq0EJ6gLIriFY+Gxdl2Y4lSo7FmpxB +87bRCLpC3mxQltNm97ZysmS4I4diYhPDSS/2acKeH2cBgAtQVG9KsuZ41qxUQ10 EY8= -----END NEW CERTIFICATE REQUEST-----

2) If the above data is in ASCII, how can i convert it to BSTR, as ICertRequest2::Submit requires the data to be unicode string.

3) Can i convert the ASCII data directly to BSTR

Thanks Raj

A: 

US-ASCII is a subset of UTF-8. The encoded form of any ASCII character is the UTF-8 encoding, so no conversion is needed.

Simply pass the string as-is, setting the CR_IN_BASE64HEADER flag.

erickson
Hello Erickson - Thank you for your answer.I donot know whether i am confused here for no reasons. I am reading my CSR from disk. I am reading the CSR as two buffer typeschar* mDataBuffer1;wchar_t* mDataBuffer;I am getting the lengths for the first char* as 548 and wchar_t* as 274; The second case's length is calculated belowRequestBuff = SysAllocString(mDataBuffer);->548 as returned by CreateFile fnlong len = SysStringLen(RequestBuff);->274Which of my declaration should i need to follow?I am sure that the secons one is wrong. Should i have to declare as char* and proceedThank youRaj
Raj
Hi Raj. I'm not sure I follow your question exactly, but I believe you should pass a char* with length of 548.
erickson
Hello Erickson - I am trying the followin1. Read the CSR from disk which is char* DataBuffer2. bstrRequest = SysAllocString(DataBuffer); If i keep the CSR as char* then SysAllocString throws an error as it is expecting only wchar_t* instead of char*; So this prompted me to change the char* to wchar_t*3. hr = pCertRequest->Submit(CR_IN_BASE64HEADER|CR_IN_PKCS10, bstrRequest, bstrAttribute, bstrCA, So thats the reason why i wanted to change my string type? I am making any sense?ThanksRaj
Raj
A: 

Either:

  1. Use MultiByteToWideChar before calling SysAllocString (or SysAllocStringLen)

  2. Use _bstr_t or CComBSTR which are C++ wrappers for BSTRs.

Rasmus Faber
Hello Rasmus, Thanks; I am using your option 1. But i am not sure what option i should use for __in UINT CodePage,__in DWORD dwFlags,I am using CP_ACP (default) and using zero for the flags. For my case, do you think these options are ok? MS warns about CP_ACP as a varying one from PC to PC. If i want to configure the PC to keep it as constant, iS there a way to do this? Thanks
Raj
It doesn't matter at all which flags you use, since your data is pure ASCII (ie. no characters with values >127). If you are worried about the warnings, just use CP_UTF8. If you want to know more about codepages there is a short article here: http://blogs.msdn.com/oldnewthing/archive/2005/03/08/389527.aspx
Rasmus Faber