/// <summary> /// Initializes a new instance of <see cref="ProtectionDescriptor"/> given a descriptor string /// and information on how to interpret that string. /// </summary> /// <param name="descriptorString">A protection descriptor rule string or a registered display /// name for a descriptor rule string stored in the registry.</param> /// <param name="creationFlags">Flags which control how <paramref name="descriptorString"/> is /// to be interpreted.</param> public ProtectionDescriptor(string descriptorString, ProtectionDescriptorCreationFlags creationFlags) { // param checks if (descriptorString == null) { throw new ArgumentNullException(nameof(descriptorString)); } if ((creationFlags & (ProtectionDescriptorCreationFlags.NamedDescriptor | ProtectionDescriptorCreationFlags.UseMachineRegistry)) != 0) { throw new ArgumentOutOfRangeException(nameof(creationFlags)); } // handle creation int ntstatus = UnsafeNativeMethods.NCryptCreateProtectionDescriptor( pwszDescriptorString: descriptorString, dwFlags: creationFlags, phDescriptor: out _descriptorHandle); CryptoUtil.AssertSuccess(ntstatus); CryptoUtil.AssertSafeHandleIsValid(_descriptorHandle); }
public static extern int NCryptCreateProtectionDescriptor( [In, MarshalAs(UnmanagedType.LPWStr)] string pwszDescriptorString, [In] ProtectionDescriptorCreationFlags dwFlags, [Out] out SafeProtectionDescriptorHandle phDescriptor);