SymmetricAlgorithm.Clear 方法

定義

釋放 SymmetricAlgorithm 類別使用的所有資源。Releases all resources used by the SymmetricAlgorithm class.

public:
 void Clear();
public void Clear ();
member this.Clear : unit -> unit
Public Sub Clear ()

備註

請注意,使用衍生類別時,不是從安全性的觀點來看,只要在使用完物件之後強制執行垃圾收集。Note that when using derived classes, it is not enough, from a security perspective, to simply force a garbage collection after you have finished using the object. 您必須在物件上明確呼叫 Clear 方法,才能釋放物件內的任何敏感性資料。You must explicitly call the Clear method on the object to zero out any sensitive data within the object before it is released. 請注意,垃圾收集並不會將所收集物件的內容零出來,而只會將記憶體標示為可供重新配置。Note that garbage collection does not zero out the contents of collected objects but simply marks the memory as available for reallocation. 因此,垃圾收集物件內所包含的資料可能仍會出現在未配置記憶體的記憶體堆積中。Thus the data contained within a garbage collected object may still be present in the memory heap in unallocated memory. 在密碼編譯物件的案例中,此資料可能包含機密資訊,例如金鑰資料或純文字區塊。In the case of cryptographic objects, this data could contain sensitive information such as key data or a block of plain text.

.NET Framework 中保存敏感性資料的所有密碼編譯類別都會執行 Clear 方法。All cryptographic classes in the .NET Framework that hold sensitive data implement a Clear method. 當呼叫時,Clear 方法會以零覆寫物件中的所有機密資料,然後釋放物件,以便安全地進行垃圾收集。When called, the Clear method overwrites all sensitive data within the object with zeros and then releases the object so that it can be safely garbage collected. 當物件已清空並釋出時,您應該呼叫 Dispose 方法,並將 disposing 參數設定為 True 來處置與物件相關聯的所有 managed 和非受控資源。When the object has been zeroed and released, you should then call the Dispose method with the disposing parameter set to True to dispose of all managed and unmanaged resources associated with the object.

適用於

另請參閱