364 {
365
366 fixed (char* value3 = uiPolicy.CreationTitle)
367 {
368 string? friendlyName = uiPolicy.FriendlyName;
369 char* intPtr;
370 string? description;
371 global::Interop.NCrypt.NCRYPT_UI_POLICY nCRYPT_UI_POLICY2;
372 if (friendlyName == null)
373 {
375 intPtr = (
value =
null);
376 description = uiPolicy.Description;
377 fixed (char* ptr = description)
378 {
379 char* value2 = ptr;
380 global::Interop.NCrypt.NCRYPT_UI_POLICY nCRYPT_UI_POLICY = default(global::Interop.NCrypt.NCRYPT_UI_POLICY);
381 nCRYPT_UI_POLICY.dwVersion = 1;
382 nCRYPT_UI_POLICY.dwFlags = uiPolicy.ProtectionLevel;
383 nCRYPT_UI_POLICY.pszCreationTitle =
new IntPtr(value3);
384 nCRYPT_UI_POLICY.pszFriendlyName =
new IntPtr(
value);
385 nCRYPT_UI_POLICY.pszDescription =
new IntPtr(value2);
386 nCRYPT_UI_POLICY2 = nCRYPT_UI_POLICY;
387 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptSetProperty(keyHandle,
"UI Policy", &nCRYPT_UI_POLICY2,
sizeof(global::Interop.NCrypt.NCRYPT_UI_POLICY),
CngPropertyOptions.Persist);
388 if (errorCode != 0)
389 {
390 throw errorCode.ToCryptographicException();
391 }
392 }
393 }
394 else
395 {
396 fixed (char* ptr2 = &friendlyName.GetPinnableReference())
397 {
399 intPtr = (
value = ptr2);
400 description = uiPolicy.Description;
401 fixed (char* ptr = description)
402 {
403 char* value2 = ptr;
404 global::Interop.NCrypt.NCRYPT_UI_POLICY nCRYPT_UI_POLICY = default(global::Interop.NCrypt.NCRYPT_UI_POLICY);
405 nCRYPT_UI_POLICY.dwVersion = 1;
406 nCRYPT_UI_POLICY.dwFlags = uiPolicy.ProtectionLevel;
407 nCRYPT_UI_POLICY.pszCreationTitle =
new IntPtr(value3);
408 nCRYPT_UI_POLICY.pszFriendlyName =
new IntPtr(
value);
409 nCRYPT_UI_POLICY.pszDescription =
new IntPtr(value2);
410 nCRYPT_UI_POLICY2 = nCRYPT_UI_POLICY;
411 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptSetProperty(keyHandle,
"UI Policy", &nCRYPT_UI_POLICY2,
sizeof(global::Interop.NCrypt.NCRYPT_UI_POLICY),
CngPropertyOptions.Persist);
412 if (errorCode != 0)
413 {
414 throw errorCode.ToCryptographicException();
415 }
416 }
417 }
418 }
419 }
420 string useContext = uiPolicy.UseContext;
421 if (useContext == null)
422 {
423 return;
424 }
425 int cbInput = checked((useContext.Length + 1) * 2);
426 fixed (char* pbInput = useContext)
427 {
428 global::Interop.NCrypt.ErrorCode errorCode2 = global::Interop.NCrypt.NCryptSetProperty(keyHandle,
"Use Context", pbInput, cbInput,
CngPropertyOptions.Persist);
429 if (errorCode2 != 0)
430 {
431 throw errorCode2.ToCryptographicException();
432 }
433 }
434 }