319 {
320 if (creationParameters.ExportPolicy.HasValue)
321 {
323 keyHandle.SetExportPolicy(
value);
324 }
325 if (creationParameters.KeyUsage.HasValue)
326 {
327 CngKeyUsages value2 = creationParameters.KeyUsage.Value;
328 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptSetProperty(keyHandle,
"Key Usage", &value2, 4,
CngPropertyOptions.Persist);
329 if (errorCode != 0)
330 {
331 throw errorCode.ToCryptographicException();
332 }
333 }
334 if (creationParameters.ParentWindowHandle !=
IntPtr.Zero)
335 {
336 IntPtr parentWindowHandle = creationParameters.ParentWindowHandle;
337 global::Interop.NCrypt.ErrorCode errorCode2 = global::Interop.NCrypt.NCryptSetProperty(keyHandle,
"HWND Handle", &parentWindowHandle,
sizeof(IntPtr),
CngPropertyOptions.None);
338 if (errorCode2 != 0)
339 {
340 throw errorCode2.ToCryptographicException();
341 }
342 }
343 CngUIPolicy uIPolicy = creationParameters.UIPolicy;
344 if (uIPolicy != null)
345 {
347 }
348 foreach (CngProperty parameter in creationParameters.Parameters)
349 {
350 byte[] valueWithoutCopying = parameter.GetValueWithoutCopying();
351 int cbInput = ((valueWithoutCopying != null) ? valueWithoutCopying.Length : 0);
352 fixed (byte* pbInput = valueWithoutCopying.MapZeroLengthArrayToNonNullPointer())
353 {
354 global::Interop.NCrypt.ErrorCode errorCode3 = global::Interop.NCrypt.NCryptSetProperty(keyHandle, parameter.Name, pbInput, cbInput, parameter.Options);
355 if (errorCode3 != 0)
356 {
357 throw errorCode3.ToCryptographicException();
358 }
359 }
360 }
361 }
static unsafe void InitializeKeyUiPolicyProperties(SafeNCryptKeyHandle keyHandle, CngUIPolicy uiPolicy)