Security Fundamentals

This section provides an overview of the key security concepts that are essential when developing Windows applications using the Win32 and WinRT APIs.

Core Concepts

Explore the detailed guides below:

Sample Secure API Usage


// Example: Using the Windows Data Protection API (DPAPI) to encrypt data.
#include <windows.h>
#include <dpapi.h>
#include <stdio.h>

int main() {
    const BYTE *plaintext = (BYTE *)"SensitiveData";
    DATA_BLOB inBlob, outBlob;

    inBlob.pbData = (BYTE *)plaintext;
    inBlob.cbData = (DWORD)strlen((char *)plaintext) + 1;

    // Encrypt using DPAPI (user scoped)
    if (CryptProtectData(&inBlob, L"Sample", NULL, NULL, NULL, 0, &outBlob)) {
        printf("Data encrypted successfully (size: %u bytes)\n", outBlob.cbData);
        // Remember to free the outBlob.pbData with LocalFree when done.
        LocalFree(outBlob.pbData);
    } else {
        printf("Encryption failed. Error: %lu\n", GetLastError());
    }
    return 0;
}
            

Additional Resources