How does DPAPI handle memory of the output buffer from CryptProtectData/CryptUnprotectData APIs?

Xiang, Ping 21 Reputation points
2021-10-25T23:40:46.203+00:00

Hi, I'm using CryptProtectData() and CryptUnprotectData() APIs for data encryption and decryption in our App. Reading API document here: https://learn.microsoft.com/en-us/windows/win32/api/dpapi/nf-dpapi-cryptprotectdata, it's not clear why LocalFree() needs to be called against the output buffer after usage, the example code on that page does not invoke LocalFree().
What's also missing on the document (The main reason for this question) is that, how DATA_BLOB::pbData for the output is managed by DPAPI? Can I provide my own memory? If I can, how do I know the output buffer size of the encrypted data?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
{count} votes

Accepted answer
  1. Xiaopo Yang - MSFT 11,496 Reputation points Microsoft Vendor
    2021-10-26T05:30:05.667+00:00

    The Complete Example C Program: Using CryptProtectData does LocalFree pDataOut.pbData.
    NO, you cannot provide your own memory.


0 additional answers

Sort by: Most helpful