예제 #1
0
        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();
                }
            }
        }
예제 #2
0
        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();
                }
            }
        }
예제 #3
0
 private static extern NtStatus RtlDecryptData2(ref CryptoBuffer data, ref CryptoBuffer key);
예제 #4
0
 private static extern NtStatus RtlDecryptData2(ref CryptoBuffer data, ref CryptoBuffer key);