Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ ImportKeyBlob() [3/3]

static SafeNCryptKeyHandle System.Security.Cryptography.ECCng.ImportKeyBlob ( string blobType,
ReadOnlySpan< byte > keyBlob,
string curveName,
SafeNCryptProviderHandle provider )
inlinestaticpackage

Definition at line 338 of file ECCng.cs.

339 {
340 global::Interop.NCrypt.ErrorCode errorCode;
343 {
344 global::Interop.BCrypt.BCryptBufferDesc structure = default(global::Interop.BCrypt.BCryptBufferDesc);
345 global::Interop.BCrypt.BCryptBuffer structure2 = default(global::Interop.BCrypt.BCryptBuffer);
346 IntPtr intPtr = IntPtr.Zero;
347 IntPtr intPtr2 = IntPtr.Zero;
348 try
349 {
350 intPtr = Marshal.AllocHGlobal(Marshal.SizeOf(structure));
351 intPtr2 = Marshal.AllocHGlobal(Marshal.SizeOf(structure2));
352 structure2.cbBuffer = (curveName.Length + 1) * 2;
353 structure2.BufferType = global::Interop.BCrypt.CngBufferDescriptors.NCRYPTBUFFER_ECC_CURVE_NAME;
354 structure2.pvBuffer = safeUnicodeStringHandle.DangerousGetHandle();
355 Marshal.StructureToPtr(structure2, intPtr2, fDeleteOld: false);
356 structure.cBuffers = 1;
357 structure.pBuffers = intPtr2;
358 structure.ulVersion = 0;
359 Marshal.StructureToPtr(structure, intPtr, fDeleteOld: false);
360 errorCode = global::Interop.NCrypt.NCryptImportKey(provider, IntPtr.Zero, blobType, intPtr, out phKey, ref MemoryMarshal.GetReference(keyBlob), keyBlob.Length, 0);
361 }
362 finally
363 {
364 Marshal.FreeHGlobal(intPtr);
365 Marshal.FreeHGlobal(intPtr2);
366 }
367 }
368 if (errorCode != 0)
369 {
370 Exception ex = errorCode.ToCryptographicException();
371 if (errorCode == global::Interop.NCrypt.ErrorCode.NTE_INVALID_PARAMETER)
372 {
373 throw new PlatformNotSupportedException(System.SR.Format(System.SR.Cryptography_CurveNotSupported, curveName), ex);
374 }
375 throw ex;
376 }
377 return phKey;
378 }
static void StructureToPtr(object structure, IntPtr ptr, bool fDeleteOld)
static void FreeHGlobal(IntPtr hglobal)
Definition Marshal.cs:1680
static int SizeOf(object structure)
Definition Marshal.cs:697
static IntPtr AllocHGlobal(int cb)
Definition Marshal.cs:625
static string Cryptography_CurveNotSupported
Definition SR.cs:64
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
Definition SR.cs:7

References System.Runtime.InteropServices.Marshal.AllocHGlobal(), System.SR.Cryptography_CurveNotSupported, System.Runtime.InteropServices.SafeHandle.DangerousGetHandle(), System.SR.Format(), System.Runtime.InteropServices.Marshal.FreeHGlobal(), System.ReadOnlySpan< T >.Length, System.Runtime.InteropServices.Marshal.SizeOf(), System.Runtime.InteropServices.Marshal.StructureToPtr(), and System.IntPtr.Zero.