Beispiel #1
0
            internal static extern bool CryptMsgGetParam(
#endif
                SafeCryptMsgHandle hCryptMsg,
                CryptMsgParamType dwParamType,
                int dwIndex,
                IntPtr pvData,
                ref int pcbData);
 public static extern bool CryptMsgGetParam
 (
     [param: In] CryptMsgSafeHandle hCryptMsg,
     [param: In, MarshalAs(UnmanagedType.U4)] CryptMsgParamType dwParamType,
     [param: In, MarshalAs(UnmanagedType.U4)] uint dwIndex,
     [param: In] LocalBufferSafeHandle pvData,
     [param: In, Out, MarshalAs(UnmanagedType.U4)] ref uint pcbData
 );
Beispiel #3
0
        // Used for binary blobs with internal pointers.
        public static SafeHandle GetMsgParamAsMemory(this SafeCryptMsgHandle hCryptMsg, CryptMsgParamType paramType, int index = 0)
        {
            int cbData = 0;
            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, null, ref cbData))
                throw Marshal.GetLastWin32Error().ToCryptographicException();

            SafeHandle pvData = SafeHeapAllocHandle.Alloc(cbData);
            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, pvData.DangerousGetHandle(), ref cbData))
                throw Marshal.GetLastWin32Error().ToCryptographicException();

            return pvData;
        }
Beispiel #4
0
        // Used for binary blobs without internal pointers.
        public static byte[] GetMsgParamAsByteArray(this SafeCryptMsgHandle hCryptMsg, CryptMsgParamType paramType, int index = 0)
        {
            int cbData = 0;
            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, null, ref cbData))
                throw Marshal.GetLastWin32Error().ToCryptographicException();

            byte[] pvData = new byte[cbData];
            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, pvData, ref cbData))
                throw Marshal.GetLastWin32Error().ToCryptographicException();

            return pvData.Resize(cbData);
        }
Beispiel #5
0
        // Used for binary blobs with internal pointers.
        public static SafeHandle GetMsgParamAsMemory(this SafeCryptMsgHandle hCryptMsg, CryptMsgParamType paramType, int index = 0)
        {
            int cbData = 0;

            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, null, ref cbData))
            {
                throw Interop.CPError.GetLastWin32Error().ToCryptographicException();
            }

            SafeHandle pvData = SafeHeapAllocHandle.Alloc(cbData);

            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, pvData.DangerousGetHandle(), ref cbData))
            {
                throw Interop.CPError.GetLastWin32Error().ToCryptographicException();
            }

            return(pvData);
        }
Beispiel #6
0
        // Used for binary blobs without internal pointers.
        public static byte[] GetMsgParamAsByteArray(this SafeCryptMsgHandle hCryptMsg, CryptMsgParamType paramType, int index = 0)
        {
            int cbData = 0;

            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, null, ref cbData))
            {
                throw Interop.CPError.GetLastWin32Error().ToCryptographicException();
            }

            byte[] pvData = new byte[cbData];
            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, pvData, ref cbData))
            {
                throw Interop.CPError.GetLastWin32Error().ToCryptographicException();
            }

            return(pvData.Resize(cbData));
        }
 internal static extern bool CryptMsgGetParam(SafeCryptMsgHandle hCryptMsg, CryptMsgParamType dwParamType, int dwIndex, IntPtr pvData, [In, Out] ref int pcbData);
Beispiel #8
0
 internal static extern bool CryptMsgGetParam(SafeCryptMsgHandle hCryptMsg, CryptMsgParamType dwParamType, int dwIndex, [Out] byte[] pvData, [In, Out] ref int pcbData);
Beispiel #9
0
        // Used for binary blobs without internal pointers.
        public static unsafe byte[] GetMsgParamAsByteArray(this SafeCryptMsgHandle hCryptMsg, CryptMsgParamType paramType, int index = 0)
        {
            int cbData = 0;

            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, IntPtr.Zero, ref cbData))
            {
                throw Marshal.GetLastWin32Error().ToCryptographicException();
            }

            byte[] data = new byte[cbData];
            fixed(byte *pvData = data)
            {
                if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, pvData, ref cbData))
                {
                    throw Marshal.GetLastWin32Error().ToCryptographicException();
                }
            }

            return(data.Resize(cbData));
        }
Beispiel #10
0
 internal static partial bool CryptMsgGetParam(
     SafeCryptMsgHandle hCryptMsg,
     CryptMsgParamType dwParamType,
     int dwIndex,
     IntPtr pvData,
     ref int pcbData);
Beispiel #11
0
 internal static unsafe partial bool CryptMsgGetParam(
     SafeCryptMsgHandle hCryptMsg,
     CryptMsgParamType dwParamType,
     int dwIndex,
     byte *pvData,
     ref int pcbData);
Beispiel #12
0
        // Used for binary blobs with internal pointers.
        public static SafeHandle GetMsgParamAsMemory(this SafeCryptMsgHandle hCryptMsg, CryptMsgParamType paramType, int index = 0)
        {
            int cbData = 0;

            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, IntPtr.Zero, ref cbData))
            {
                throw Marshal.GetLastPInvokeError().ToCryptographicException();
            }

            SafeHandle pvData = SafeHeapAllocHandle.Alloc(cbData);

            if (!Interop.Crypt32.CryptMsgGetParam(hCryptMsg, paramType, index, pvData.DangerousGetHandle(), ref cbData))
            {
                Exception e = Marshal.GetLastPInvokeError().ToCryptographicException();
                pvData.Dispose();
                throw e;
            }

            return(pvData);
        }