ProtectedMemory ProtectedMemory ProtectedMemory ProtectedMemory Class

Definice

Poskytuje metody pro ochranu a zrušení ochrany paměti.Provides methods for protecting and unprotecting memory. Tato třída nemůže dědit.This class cannot be inherited.

public ref class ProtectedMemory sealed
public sealed class ProtectedMemory
type ProtectedMemory = class
Public NotInheritable Class ProtectedMemory
Dědičnost
ProtectedMemoryProtectedMemoryProtectedMemoryProtectedMemory

Příklady

Následující příklad ukazuje, jak používat ochranu dat.The following example shows how to use data protection.

#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 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 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
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 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

Poznámky

Tato třída poskytuje přístup k na Data Protection API (DPAPI) k dispozici ve Windows XP a novějších operačních systémech.This class provides access to the Data Protection API (DPAPI) available in the Windows XP and later operating systems. Toto je služba, která je k dispozici v operačním systému a další knihovny se nevyžaduje.This is a service that is provided by the operating system and does not require additional libraries. To zajišťuje šifrování pro citlivá data v paměti.It provides encryption for sensitive data in memory.

Třídy se skládá ze dvou obálky pro nespravované DPAPI Protect a Unprotect.The class consists of two wrappers for the unmanaged DPAPI, Protect and Unprotect. Tyto dvě metody slouží k šifrování a dešifrování dat v paměti.These two methods can be used to encrypt and decrypt data in memory.

Metody

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Určuje, zda se zadaný objekt rovná aktuálnímu objektu.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Slouží jako výchozí funkce hash.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Získá Type aktuální instance.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Vytvoří Mělkou kopii aktuální Object.Creates a shallow copy of the current Object.

(Inherited from Object)
Protect(Byte[], MemoryProtectionScope) Protect(Byte[], MemoryProtectionScope) Protect(Byte[], MemoryProtectionScope) Protect(Byte[], MemoryProtectionScope)

Chrání zadaná data.Protects the specified data.

ToString() ToString() ToString() ToString()

Vrací řetězec, který představuje aktuální objekt.Returns a string that represents the current object.

(Inherited from Object)
Unprotect(Byte[], MemoryProtectionScope) Unprotect(Byte[], MemoryProtectionScope) Unprotect(Byte[], MemoryProtectionScope) Unprotect(Byte[], MemoryProtectionScope)

Odemkne data v paměti, který byl chráněn pomocí Protect(Byte[], MemoryProtectionScope) metody.Unprotects data in memory that was protected using the Protect(Byte[], MemoryProtectionScope) method.

Platí pro