예제 #1
0
 public static extern NTStatus BCryptGetProperty(
     SafeHandle hObject,
     string property,
     [Out, MarshalAs(UnmanagedType.LPArray)] byte[] output,
     int outputSize,
     out int resultSize,
     BCryptGetPropertyFlags flags = BCryptGetPropertyFlags.None);
예제 #2
0
        /// <summary>
        /// Retrieves the value of a named property for a CNG object.
        /// </summary>
        /// <typeparam name="T">The type of struct to return the property value as.</typeparam>
        /// <param name="hObject">A handle that represents the CNG object to obtain the property value for.</param>
        /// <param name="propertyName">A pointer to a null-terminated Unicode string that contains the name of the property to retrieve. This can be one of the predefined <see cref="PropertyNames"/> or a custom property identifier.</param>
        /// <param name="flags">A set of flags that modify the behavior of this function. No flags are defined for this function.</param>
        /// <returns>The property value.</returns>
        public static T BCryptGetProperty <T>(SafeHandle hObject, string propertyName, BCryptGetPropertyFlags flags = BCryptGetPropertyFlags.None)
            where T : struct
        {
            ArraySegment <byte> value = BCryptGetProperty(hObject, propertyName, flags);

            unsafe
            {
                fixed(byte *pValue = value.Array)
                {
                    IntPtr pValuePtr = new IntPtr(pValue + value.Offset);

#if NETSTANDARD2_0_ORLATER || NETFX_CORE
                    return(Marshal.PtrToStructure <T>(pValuePtr));
#else
                    return((T)Marshal.PtrToStructure(pValuePtr, typeof(T)));
#endif
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Retrieves the value of a named property for a CNG object.
        /// </summary>
        /// <param name="hObject">A handle that represents the CNG object to obtain the property value for.</param>
        /// <param name="propertyName">A pointer to a null-terminated Unicode string that contains the name of the property to retrieve. This can be one of the predefined <see cref="PropertyNames"/> or a custom property identifier.</param>
        /// <param name="flags">A set of flags that modify the behavior of this function. No flags are defined for this function.</param>
        /// <returns>The property value.</returns>
        public static ArraySegment <byte> BCryptGetProperty(SafeHandle hObject, string propertyName, BCryptGetPropertyFlags flags = BCryptGetPropertyFlags.None)
        {
            int length;

            BCryptGetProperty(hObject, propertyName, IntPtr.Zero, 0, out length, flags).ThrowOnError();
            byte[] result = new byte[length];
            BCryptGetProperty(hObject, propertyName, result, result.Length, out length, flags).ThrowOnError();
            return(new ArraySegment <byte>(result, 0, length));
        }
예제 #4
0
        /// <summary>
        /// Retrieves the value of a named property for a CNG object.
        /// </summary>
        /// <typeparam name="T">The type of struct to return the property value as.</typeparam>
        /// <param name="hObject">A handle that represents the CNG object to obtain the property value for.</param>
        /// <param name="propertyName">A pointer to a null-terminated Unicode string that contains the name of the property to retrieve. This can be one of the predefined <see cref="PropertyNames"/> or a custom property identifier.</param>
        /// <param name="flags">A set of flags that modify the behavior of this function. No flags are defined for this function.</param>
        /// <returns>The property value.</returns>
        public static T BCryptGetProperty <T>(SafeHandle hObject, string propertyName, BCryptGetPropertyFlags flags = BCryptGetPropertyFlags.None)
            where T : struct
        {
            ArraySegment <byte> value = BCryptGetProperty(hObject, propertyName, flags);

            unsafe
            {
                fixed(byte *pValue = value.Array)
                {
                    IntPtr pValuePtr = new IntPtr(pValue + value.Offset);

                    return((T)Marshal.PtrToStructure(pValuePtr, typeof(T)));
                }
            }
        }
예제 #5
0
 public static extern NTSTATUS BCryptGetProperty(
     SafeHandle hObject,
     string property,
     [Out, MarshalAs(UnmanagedType.LPArray)] byte[] output,
     int outputSize,
     out int resultSize,
     BCryptGetPropertyFlags flags = BCryptGetPropertyFlags.None);