ProtectedMemory.Protect(Byte[], MemoryProtectionScope) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Védi a megadott adatokat.
public:
static void Protect(cli::array <System::Byte> ^ userData, System::Security::Cryptography::MemoryProtectionScope scope);
public static void Protect(byte[] userData, System.Security.Cryptography.MemoryProtectionScope scope);
static member Protect : byte[] * System.Security.Cryptography.MemoryProtectionScope -> unit
Public Shared Sub Protect (userData As Byte(), scope As MemoryProtectionScope)
Paraméterek
- userData
- Byte[]
A védelem érdekében a memóriában lévő adatokat tartalmazó bájttömb. A tömbnek 16 bájt többszörösének kell lennie.
- scope
- MemoryProtectionScope
A memóriavédelem hatókörét meghatározó enumerálási értékek egyike.
Kivételek
userData 16 bájt hosszúságúnak vagy 16 bájt többszörösének kell lennie.
Az operációs rendszer nem támogatja ezt a módszert. Ez a módszer csak a 2000-Windows vagy újabb operációs rendszerekkel használható.
userData az null.
Példák
Az alábbi kód példája az adatvédelem használatát mutatja be.
#using <System.Security.dll>
using namespace System;
using namespace System::Security::Cryptography;
int main()
{
// Create the original data to be encrypted (The data length should be a multiple of 16).
array<Byte>^secret = {1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4};
// Encrypt the data in memory. The result is stored in the same array as the original data.
ProtectedMemory::Protect( secret, MemoryProtectionScope::SameLogon );
// Decrypt the data in memory and store in the original array.
ProtectedMemory::Unprotect( secret, MemoryProtectionScope::SameLogon );
}
using System;
using System.Security.Cryptography;
public class MemoryProtectionSample
{
public static void Main()
{
// Create the original data to be encrypted (The data length should be a multiple of 16).
byte [] secret = { 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 };
// Encrypt the data in memory. The result is stored in the same array as the original data.
ProtectedMemory.Protect( secret, MemoryProtectionScope.SameLogon );
// Decrypt the data in memory and store in the original array.
ProtectedMemory.Unprotect( secret, MemoryProtectionScope.SameLogon );
}
}
Imports System.Security.Cryptography
Public Class MemoryProtectionSample
Public Shared Sub Main()
' Create the original data to be encrypted (The data length should be a multiple of 16).
Dim secret As Byte() = {1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}
' Encrypt the data in memory. The result is stored in the same array as the original data.
ProtectedMemory.Protect(secret, MemoryProtectionScope.SameLogon)
' Decrypt the data in memory and store in the original array.
ProtectedMemory.Unprotect(secret, MemoryProtectionScope.SameLogon)
End Sub
End Class
Megjegyzések
Ez a módszer a memóriában lévő adatok védelmére használható. Vegye figyelembe, hogy a metódus nem készít másolatot az adatokról, hanem a helyén titkosítja a bájttömböt. A userData paraméternek 16 bájt hosszúságúnak vagy 16 bájt többszörösének kell lennie.
Ennek a módszernek a támogatása a Windows XP és újabb operációs rendszerekben érhető el.