ProtectedMemory.Unprotect(Byte[], MemoryProtectionScope) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
取消对使用 Protect(Byte[], MemoryProtectionScope) 方法保护的内存中的数据的保护。
public:
static void Unprotect(cli::array <System::Byte> ^ encryptedData, System::Security::Cryptography::MemoryProtectionScope scope);
public static void Unprotect (byte[] encryptedData, System.Security.Cryptography.MemoryProtectionScope scope);
static member Unprotect : byte[] * System.Security.Cryptography.MemoryProtectionScope -> unit
Public Shared Sub Unprotect (encryptedData As Byte(), scope As MemoryProtectionScope)
参数
- encryptedData
- Byte[]
要解密的内存中的字节数组。
- scope
- MemoryProtectionScope
指定内存保护范围的枚举值之一。
例外
该操作系统不支持此方法。 此方法仅可用于 Windows 2000 或更高版本的操作系统。
encryptedData
为 null
。
示例
以下示例演示如何使用数据保护。
#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
注解
此方法可用于取消加密使用 Protect 方法加密的内存中的数据。
Windows XP 和更高版本的操作系统中提供了对此方法的支持。