0

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

Raj
  • 1,113
  • 1
  • 17
  • 34

2 Answers2

0

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
  • 265,237
  • 58
  • 395
  • 493
  • 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 types char* 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 below RequestBuff = SysAllocString(mDataBuffer);->548 as returned by CreateFile fn long len = SysStringLen(RequestBuff);->274 Which 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 proceed Thank you Raj – Raj Jun 11 '09 at 21:42
  • Hi Raj. I'm not sure I follow your question exactly, but I believe you should pass a char* with length of 548. – erickson Jun 11 '09 at 22:25
  • Hello Erickson - I am trying the followin 1. Read the CSR from disk which is char* DataBuffer 2. 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, &vDispositionCode); So thats the reason why i wanted to change my string type? I am making any sense? Thanks Raj – Raj Jun 11 '09 at 22:43
0

Either:

  1. Use MultiByteToWideChar before calling SysAllocString (or SysAllocStringLen)

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

Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
  • 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 Jun 12 '09 at 19:12
  • 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 Jun 12 '09 at 20:35