CredUnprotectA function (wincred.h)

The CredUnprotect function decrypts credentials that were previously encrypted by using the CredProtect function. The credentials must have been encrypted in the same security context in which CredUnprotect is called.


BOOL CredUnprotectA(
  [in]      BOOL  fAsSelf,
  [in]      LPSTR pszProtectedCredentials,
  [in]      DWORD cchProtectedCredentials,
  [out]     LPSTR pszCredentials,
  [in, out] DWORD *pcchMaxChars


[in] fAsSelf

Set to TRUE to specify that the credentials were encrypted in the security context of the current process. Set to FALSE to specify that credentials were encrypted in the security context of the calling thread security context.

[in] pszProtectedCredentials

A pointer to a string that specifies the encrypted credentials.

[in] cchProtectedCredentials

The size, in characters, of the pszProtectedCredentials buffer.

[out] pszCredentials

A pointer to a string that, on output, receives the decrypted credentials.

[in, out] pcchMaxChars

The size, in characters of the pszCredentials buffer. On output, if the pszCredentials is not of sufficient size to receive the encrypted credentials, this parameter specifies the required size, in characters, of the pszCredentials buffer.

Return value

TRUE if the function succeeds; otherwise, FALSE.

For extended error information, call the GetLastError function. The following table shows common values for the GetLastError function.

Return code/value Description
The security context used to encrypt the credentials is different from the security context used to decrypt the credentials.
The pszCredentials buffer was of insufficient size.



The wincred.h header defines CredUnprotect as an alias which automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.


Requirement Value
Minimum supported client Windows Vista [desktop apps only]
Minimum supported server Windows Server 2008 [desktop apps only]
Target Platform Windows
Header wincred.h
Library Advapi32.lib
DLL Advapi32.dll