Quantcast
Channel: Exchange Server Development forum
Viewing all articles
Browse latest Browse all 7132

C++ CryptProtectData - Exchange MAPI Profile - How to set variables

$
0
0

Hi,

i am trying to use the CryptProtectData function so i can encrypt my password and use it inside my MAPI profile. I am using these 2  ttp://blogs.msdn.com/b/dvespa/archive/2013/05/21/how-to-mfcmapi-create-mapi-profile-exchange-2013.aspx
and ttp://blogs.msdn.com/b/dvespa/archive/2013/07/15/create-profile-connect-mfcmapi-to-office-365.aspx articles for connecting to my hosted exchange(2013) account with MFCMAPI. When setting all my properties i am being prompted for my credentials, and there i got the problem that the field provided for the domain is too short for my domain. So i have to set these properties manually (howto is described in the second article).

Now i need to set my username and password in my MAPI profile and it seems like i need to encrpyt the password by my own (i have to build an application to do so).  I am using "MAPI Download configuration guidance.docx" (can be downloaded from - www. microsoft.com/en-us/download/details.aspx?id=39045 - the piece of code i am using is at the end of the document) for building my own application to encrypt my password (i am using the smaller example for just encrypting the password, not for creating the whole profile). There i got a lot of problems, the application didnt run on a 32bit Windows, than the crypt32.lib was missing (i had to create it by my own) and so on. Now i got it running on a 64bit machine, but now i am not sure how to provide my data to the program.  

I have the following code:

std::string stemp = "myPassword"; std::wstring stemp1 = std::wstring(stemp.begin(), stemp.end()); LPWSTR pwszPassword = (LPWSTR)stemp1.c_str();//stemp.c_str();// HRESULT hr = S_OK; DATA_BLOB dataBlobIn = {0}; DATA_BLOB dataBlobOut = {0}; SPropValue propValues[2] = {0}; // Validate parameters // Encrypt password based on local user authentication dataBlobIn.pbData = (LPBYTE)pwszPassword; // Include NULL character dataBlobIn.cbData = (::wcslen(pwszPassword) + 1) * sizeof(WCHAR);

CryptProtectData(
            &dataBlobIn,
            NULL,
            NULL,
            NULL,
            NULL,
            0,
            &dataBlobOut);

std::cout<<"\n-- ";
  std::wcout<<(dataBlobOut.cbData);
  std::cout<<" --\n";
  std::wcout<<(dataBlobOut.pbData);


Now when outputting these 2 values, for dataBlobOut.cbData i mostly get "230" (i thought that this might change when i change the size of the password, but it does not, it has the same value for passwords like "aaa", "bbb","cc" ...), and for dataBlobOut.pbData i get a Hexadezimal value  (something like 0x2cde50) i think it is the address of the variable, since pbData is a pointer.

Since i am getting the exact same values for  diffrente passwords i assume that my approach is not right. But what do i have to change to get my encrypted password so i can fill the property PR_PROFILE_AUTH_PASSWORD ?

Kind regards

P.s. since i need to verify my account to post links, but i cannot because the thread for verifying is closed i will just cripple the links

Semir



Viewing all articles
Browse latest Browse all 7132

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>