Share via


SecureZeroMemory2 函式

SecureZeroMemory2 函式會以保證安全的方式,以零填滿記憶體區塊。

重要

某些資訊與發行前版本產品有關,在發行前版本產品可能經過大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。

參數

Param 目的地 [out]

記憶體區塊起始位址的指標,以零填滿。

Param Length [in]

要填滿零的記憶體區塊大小,以位元組為單位。

語法

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

備註

此 API 是 FillVolatileMemory便利包裝函式,與 ZeroVolatileMemory 相同。 如需詳細資訊,請參閱 FillVolatileMemory備註。

注意

此函式適用於所有版本的 Windows,而不只是最新版本。 您必須取用最新的 SDK,才能從 winbase.h 標頭取得函式宣告。 您也需要來自最新 SDK 的連結庫 (volatileaccessu.lib)。 不過,產生的二進位檔將會在舊版 Windows 上正常執行。

範例

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));

需求

最低支援的用戶端: Windows 11 Insider Preview 組建 TBD

標頭: winbase.h (包括 Winbase.h)

核心模式連結庫: volatileaccessk.lib

使用者模式連結庫: volatileaccessu.lib

另請參閱