Share via


Función SecureZeroMemory2

La función SecureZeroMemory2 rellena un bloque de memoria con ceros de forma que se garantiza que sea seguro.

Importante

Parte de la información hace referencia a un producto de versión preliminar que puede sufrir importantes modificaciones antes de que se publique la versión comercial. Microsoft no proporciona ninguna garantía, expresa o implícita, con respecto a la información proporcionada aquí.

Parámetros

Destino del parámetro [out]

Un puntero a la dirección inicial del bloque de memoria que se rellenará con ceros.

Longitud del parámetro [in]

Tamaño del bloque de memoria que se rellenará con ceros, en bytes.

Sintaxis

volatile void*
  SecureZeroMemory2 (
    _Out_writes_bytes_all_(Length) volatile void* Destination,
    SIZE_T Length
  );

Comentarios

Esta API es un contenedor de conveniencia alrededor de FillVolatileMemory y es idéntico a ZeroVolatileMemory. Consulte los comentarios de FillVolatileMemory para obtener más información.

Nota:

Esta función funciona en todas las versiones de Windows, no solo en la más reciente. Es necesario consumir el SDK más reciente para obtener la declaración de función del encabezado winbase.h. También se necesita la biblioteca (volatileaccessu.lib) del SDK más reciente. Sin embargo, el binario resultante se ejecutará correctamente en versiones anteriores de Windows.

Ejemplo

UCHAR SensitiveData[100];

// Imagine we temporarily store some sensitive cryptographic
// material in a buffer.

StoreCryptographicKey(&SensitiveData);
DoCryptographicOperation(&SensitiveData);

// Now that we are done using the sensitive data we want to
// erase it from the stack. We cannot call FillMemory because
// if the compiler realizes that "SensitiveData" is not
// referenced again the compiler can remove the call to FillMemory.
// Instead we can call SecureZeroMemory2, ZeroVolatileMemory, or FillVolatileMemory
// (the former two are convienence wrappers around the latter). These
// calls will not be optimized away by the compiler.
// Note that SecureZeroMemory2 performs better than the old
// SecureZeroMemory API.

SecureZeroMemory2(&SensitiveData, sizeof(SensitiveData));

Requisitos

Cliente mínimo admitido: compilación preliminar de Windows 11 Insider

Encabezado: winbase.h (incluir Winbase.h)

Biblioteca en modo kernel: volatileaccessk.lib

Biblioteca en modo de usuario: volatileaccessu.lib

Consulte también