title: Decrypt WEP wlan profile key using CryptUnprotectData
body: <p>I am trying to decrypt WEP profile's key using <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa380882%28v=vs.85%29.aspx">CryptUnprotectData</a>. The way I fetched the profile key is by exporting the profile using netsh.</p>
  
  <pre><code>netsh wlan export profile name="MyWEP" folder="./"
  </code></pre>
  
  <p>For now, I manually copied the key material from the .xml file generated by the netsh command to my program. And the way, I am decrypting is -</p>
  
  <pre><code>DATA_BLOB DataOut, DataVerify;
  DataOut.cbData = encryptData.length();
  DataOut.pbData = (BYTE*)("I_Manually_Copy_The_WEP_Key_Here");
  
  if (CryptUnprotectData( &amp;DataOut,
                          NULL,
                          NULL,
                          NULL,
                          NULL,
                          0,
                          &amp;DataVerify))
  {
      printf("The decrypted data is: %s\n", DataVerify.pbData);
  }
  else
  {
      printf("Failed. Error Code: %d", GetLastError());
  }
  </code></pre>
  
  <p>But I am getting the error code <strong>13</strong> citing Invalid Data. What am I doing wrong ? On Win 7 and later, I can directly use <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/ms706738%28v=vs.85%29.aspx">WlanGetProfile</a> with the parameter <strong>WLAN_PROFILE_GET_PLAINTEXT_KEY</strong> . But I have <strong>NO</strong> option on <strong>Vista</strong> than to use the CryptUnprotectData function. I have seen similar posts <a href="http://social.msdn.microsoft.com/Forums/en/vistawirelesssdk/thread/ad10453a-68a8-4f69-bcc8-76aeae9085f7">here</a>, <a href="http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/7815b530-65e7-4404-888a-02d929439094/">here</a> but didn't get much useful information. Also, I am using the same system with same user log on credentials. Could any one please suggest me how to proceed ?</p>
  
  <p>PS: I have posted the same question on Windows Desktop SDK forums, but haven't got response yet. Trying my luck on SO.</p>