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 和更新版本的作業系統提供此方法的支援。