예제 #1
0
파일: Cng.cs 프로젝트: kunitdmi/corefx
        // Note: input and output are allowed to be the same buffer. BCryptDecrypt will correctly do the decryption in place according to CNG documentation.
        public static int BCryptDecrypt(this SafeKeyHandleBCrypt hKey, byte[] input, int inputOffset, int inputCount, byte[] iv, byte[] output, int outputOffset, int outputCount)
        {
            Debug.Assert(input != null);
            Debug.Assert(inputOffset >= 0);
            Debug.Assert(inputCount >= 0);
            Debug.Assert(inputCount <= input.Length - inputOffset);
            Debug.Assert(output != null);
            Debug.Assert(outputOffset >= 0);
            Debug.Assert(outputCount >= 0);
            Debug.Assert(outputCount <= output.Length - outputOffset);

            unsafe
            {
                fixed(byte *pbInput = input)
                {
                    fixed(byte *pbOutput = output)
                    {
                        int      cbResult;
                        NTSTATUS ntStatus = Interop.BCryptDecrypt(hKey, pbInput + inputOffset, inputCount, IntPtr.Zero, iv, iv == null ? 0 : iv.Length, pbOutput + outputOffset, outputCount, out cbResult, 0);

                        if (ntStatus != NTSTATUS.STATUS_SUCCESS)
                        {
                            throw CreateCryptographicException(ntStatus);
                        }
                        return(cbResult);
                    }
                }
            }
        }
예제 #2
0
파일: Cng.cs 프로젝트: kunitdmi/corefx
 public static extern unsafe NTSTATUS BCryptDecrypt(SafeKeyHandleBCrypt hKey, byte *pbInput, int cbInput, IntPtr paddingInfo, [In, Out] byte[] pbIV, int cbIV, byte *pbOutput, int cbOutput, out int cbResult, int dwFlags);
예제 #3
0
파일: Cng.cs 프로젝트: kunitdmi/corefx
 public static extern NTSTATUS BCryptImportKey(SafeAlgorithmHandle hAlgorithm, IntPtr hImportKey, string pszBlobType, out SafeKeyHandleBCrypt hKey, IntPtr pbKeyObject, int cbKeyObject, byte[] pbInput, int cbInput, int dwFlags);