MSDN Docs

Security API Reference

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.

APIDescriptionHeader
LogonUserCreates a logon session for a user.winbase.h
CheckTokenMembershipDetermines if a token contains a specific SID.securitybaseapi.h
AdjustTokenPrivilegesEnables or disables privileges in a token.winbase.h
InitializeSecurityDescriptorInitializes a security descriptor.winnt.h
SetSecurityInfoSets security information for an object.aclapi.h
CryptAcquireContextAcquires a handle to a cryptographic service provider.wincrypt.h
BCryptEncryptEncrypts data using the CNG API.bcrypt.h
AuthzOpenResourceManagerCreates a resource manager for authorization.authz.h
AuditFreeFrees 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.

Authorization

Authorization determines access rights. The Authz and Access Control Lists (ACL) APIs are central.

#include <aclapi.h>
PSECURITY_DESCRIPTOR sd = NULL;
SetSecurityInfo(
    hFile,
    SE_FILE_OBJECT,
    DACL_SECURITY_INFORMATION,
    NULL,
    NULL,
    pDACL,
    NULL);

Refer to the Authorization documentation for advanced usage.

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.