Overview
The Windows Security API provides a comprehensive set of functions and structures that enable developers to manage authentication, access control, encryption, and auditing on Windows platforms.
| API | Description | Header |
|---|---|---|
LogonUser | Creates a logon session for a user. | winbase.h |
CheckTokenMembership | Determines if a token contains a specific SID. | securitybaseapi.h |
AdjustTokenPrivileges | Enables or disables privileges in a token. | winbase.h |
InitializeSecurityDescriptor | Initializes a security descriptor. | winnt.h |
SetSecurityInfo | Sets security information for an object. | aclapi.h |
CryptAcquireContext | Acquires a handle to a cryptographic service provider. | wincrypt.h |
BCryptEncrypt | Encrypts data using the CNG API. | bcrypt.h |
AuthzOpenResourceManager | Creates a resource manager for authorization. | authz.h |
AuditFree | Frees memory allocated for audit events. | winnt.h |
Authentication
Authentication functions verify the identity of a user or process. Commonly used APIs include:
#include <windows.h>
BOOL result = LogonUserW(
L"username",
L"DOMAIN",
L"Password123!",
LOGON32_LOGON_INTERACTIVE,
LOGON32_PROVIDER_DEFAULT,
&tokenHandle);
See the full Authentication guide for more details.
Cryptography
The Windows Cryptography API (CryptoAPI) and Cryptography Next Generation (CNG) provide powerful tools for encryption, hashing, and key management.
#include <bcrypt.h>
BCRYPT_ALG_HANDLE hAlg = NULL;
BCryptOpenAlgorithmProvider(&hAlg, BCRYPT_AES_ALGORITHM, NULL, 0);
// ...
BCryptEncrypt(hAlg, plainText, plainLen, NULL, iv, ivLen, cipherText, cipherLen, &resultLen, 0);
Explore the Cryptography section for a complete reference.
Auditing
Auditing APIs allow applications to generate and manage audit events.
#include <winnt.h>
AUDIT_EVENT_INFO info = {0};
info.EventType = EVENTLOG_ERROR_TYPE;
info.StringCount = 1;
info.String[0] = L"An unexpected error occurred.";
ReportEventW(hEventLog, info.EventType, 0, 0xDEADBEEF, NULL, 1, 0, info.String, NULL);
Read the Auditing guide for best practices.