internal static NtStatus RtlDecryptData2(byte[] encryptedData, byte[] key, out byte[] decryptedData) { // RtlDecryptData2 writes data to the input buffer, so we make a copy of it to be safe decryptedData = (byte[])encryptedData.Clone(); GCHandle dataPin = GCHandle.Alloc((object)decryptedData, GCHandleType.Pinned); GCHandle keyPin = GCHandle.Alloc((object)key, GCHandleType.Pinned); try { CryptoBuffer keyBuffer = new CryptoBuffer(keyPin.AddrOfPinnedObject(), key.Length); CryptoBuffer dataBuffer = new CryptoBuffer(dataPin.AddrOfPinnedObject(), decryptedData.Length); NtStatus result = RtlDecryptData2(ref dataBuffer, ref keyBuffer); return(result); } finally { if (dataPin != null && dataPin.IsAllocated) { dataPin.Free(); } if (keyPin != null && keyPin.IsAllocated) { keyPin.Free(); } } }
internal static NtStatus RtlDecryptData2(byte[] encryptedData, byte[] key, out byte[] decryptedData) { // RtlDecryptData2 writes data to the input buffer, so we make a copy of it to be safe decryptedData = (byte[])encryptedData.Clone(); GCHandle dataPin = GCHandle.Alloc((object)decryptedData, GCHandleType.Pinned); GCHandle keyPin = GCHandle.Alloc((object)key, GCHandleType.Pinned); try { CryptoBuffer keyBuffer = new CryptoBuffer(keyPin.AddrOfPinnedObject(), key.Length); CryptoBuffer dataBuffer = new CryptoBuffer(dataPin.AddrOfPinnedObject(), decryptedData.Length); NtStatus result = RtlDecryptData2(ref dataBuffer, ref keyBuffer); return result; } finally { if (dataPin != null && dataPin.IsAllocated) { dataPin.Free(); } if (keyPin != null && keyPin.IsAllocated) { keyPin.Free(); } } }
private static extern NtStatus RtlDecryptData2(ref CryptoBuffer data, ref CryptoBuffer key);
private static extern NtStatus RtlDecryptData2(ref CryptoBuffer data, ref CryptoBuffer key);