Exemplo n.º 1
0
 public static extern SECURITY_STATUS NCryptGetProperty(
     SafeHandle hObject,
     string pszProperty,
     [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] byte[] pbOutput,
     int cbOutput,
     out int pcbResult,
     NCryptGetPropertyFlags dwFlags);
Exemplo n.º 2
0
        /// <summary>
        /// Retrieves the value of a named property for a key storage object.
        /// </summary>
        /// <typeparam name="T">The type of struct to return the property value as.</typeparam>
        /// <param name="hObject">
        /// The handle of the object to get the property for. This can be a provider handle (<see cref="SafeProviderHandle"/>) or a key handle (<see cref="SafeKeyHandle"/>).
        /// </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="KeyStoragePropertyIdentifiers"/> or a custom property identifier.
        /// </param>
        /// <param name="flags">Flags that modify function behavior.</param>
        /// <returns>The property value.</returns>
        public static T NCryptGetProperty <T>(SafeHandle hObject, string propertyName, NCryptGetPropertyFlags flags = NCryptGetPropertyFlags.None)
            where T : struct
        {
            byte[] value = NCryptGetProperty(hObject, propertyName, flags);
            unsafe
            {
                fixed(byte *pValue = value)
                {
#if NETSTANDARD2_0_ORLATER || NETFX_CORE
                    return(Marshal.PtrToStructure <T>(new IntPtr(pValue)));
#else
                    return((T)Marshal.PtrToStructure(new IntPtr(pValue), typeof(T)));
#endif
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Retrieves the value of a named property for a key storage object.
        /// </summary>
        /// <param name="hObject">
        /// The handle of the object to get the property for. This can be a provider handle (<see cref="SafeProviderHandle"/>) or a key handle (<see cref="SafeKeyHandle"/>).
        /// </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="KeyStoragePropertyIdentifiers"/> or a custom property identifier.
        /// </param>
        /// <param name="flags">Flags that modify function behavior.</param>
        /// <returns>The property value.</returns>
        public static byte[] NCryptGetProperty(SafeHandle hObject, string propertyName, NCryptGetPropertyFlags flags = NCryptGetPropertyFlags.None)
        {
            int requiredSize;

            NCryptGetProperty(hObject, propertyName, null, 0, out requiredSize, flags).ThrowOnError();
            byte[] result = new byte[requiredSize];
            NCryptGetProperty(hObject, propertyName, result, result.Length, out requiredSize, flags).ThrowOnError();
            return(result);
        }
Exemplo n.º 4
0
 public static extern SECURITY_STATUS NCryptGetProperty(
     SafeHandle hObject,
     string pszProperty,
     [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4)] byte[] pbOutput,
     int cbOutput,
     out int pcbResult,
     NCryptGetPropertyFlags dwFlags);
Exemplo n.º 5
0
 /// <summary>
 /// Retrieves the value of a named property for a key storage object.
 /// </summary>
 /// <typeparam name="T">The type of struct to return the property value as.</typeparam>
 /// <param name="hObject">
 /// The handle of the object to get the property for. This can be a provider handle (<see cref="SafeProviderHandle"/>) or a key handle (<see cref="SafeKeyHandle"/>).
 /// </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="KeyStoragePropertyIdentifiers"/> or a custom property identifier.
 /// </param>
 /// <param name="flags">Flags that modify function behavior.</param>
 /// <returns>The property value.</returns>
 public static T NCryptGetProperty <T>(SafeHandle hObject, string propertyName, NCryptGetPropertyFlags flags = NCryptGetPropertyFlags.None)
     where T : struct
 {
     byte[] value = NCryptGetProperty(hObject, propertyName, flags);
     unsafe
     {
         fixed(byte *pValue = value)
         {
             return((T)Marshal.PtrToStructure(new IntPtr(pValue), typeof(T)));
         }
     }
 }