コード例 #1
0
        public static void WriteStringUni(NCryptHandleBase handle, string propertyName, string value)
        {
            var ptr = Marshal.StringToHGlobalUni(value);

            try
            {
                if (NCrypt.NCryptSetProperty(handle, propertyName, ptr, (uint)value.Length * 2, 0u) != SECURITY_STATUS.ERROR_SUCCESS)
                {
                    throw new InvalidOperationException("Unable to set property.");
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
コード例 #2
0
        public static void WriteInt32(NCryptHandleBase handle, string propertyName, int value)
        {
            var size = Marshal.SizeOf(typeof(int));
            var ptr  = Marshal.AllocHGlobal(size);

            Marshal.WriteInt32(ptr, value);
            try
            {
                if (NCrypt.NCryptSetProperty(handle, propertyName, ptr, (uint)size, 0u) != SECURITY_STATUS.ERROR_SUCCESS)
                {
                    throw new InvalidOperationException("Unable to set property.");
                }
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }