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

◆ ImportKeyBlob() [2/2]

static unsafe SafeNCryptKeyHandle System.Security.Cryptography.CngKeyLite.ImportKeyBlob ( string blobType,
ReadOnlySpan< byte > keyBlob,
bool encrypted = false,
ReadOnlySpan< char > password = default(ReadOnlySpan<char>) )
inlinestaticpackage

Definition at line 14 of file CngKeyLite.cs.

15 {
16 global::Interop.NCrypt.ErrorCode errorCode;
18 if (encrypted)
19 {
20 using SafeUnicodeStringHandle safeUnicodeStringHandle = new SafeUnicodeStringHandle(password);
21 global::Interop.NCrypt.NCryptBuffer* ptr = stackalloc global::Interop.NCrypt.NCryptBuffer[1];
22 *ptr = new global::Interop.NCrypt.NCryptBuffer
23 {
24 BufferType = global::Interop.NCrypt.BufferType.PkcsSecret,
25 cbBuffer = checked(2 * (password.Length + 1)),
26 pvBuffer = safeUnicodeStringHandle.DangerousGetHandle()
27 };
28 if (ptr->pvBuffer == IntPtr.Zero)
29 {
30 ptr->cbBuffer = 0;
31 }
32 global::Interop.NCrypt.NCryptBufferDesc nCryptBufferDesc = default(global::Interop.NCrypt.NCryptBufferDesc);
33 nCryptBufferDesc.cBuffers = 1;
34 nCryptBufferDesc.pBuffers = (IntPtr)ptr;
35 nCryptBufferDesc.ulVersion = 0;
36 global::Interop.NCrypt.NCryptBufferDesc pParameterList = nCryptBufferDesc;
37 errorCode = global::Interop.NCrypt.NCryptImportKey(s_microsoftSoftwareProviderHandle, IntPtr.Zero, blobType, ref pParameterList, out phKey, ref MemoryMarshal.GetReference(keyBlob), keyBlob.Length, 0);
38 }
39 else
40 {
41 errorCode = global::Interop.NCrypt.NCryptImportKey(s_microsoftSoftwareProviderHandle, IntPtr.Zero, blobType, IntPtr.Zero, out phKey, ref MemoryMarshal.GetReference(keyBlob), keyBlob.Length, 0);
42 }
43 if (errorCode != 0)
44 {
45 throw errorCode.ToCryptographicException();
46 }
47 SetExportable(phKey);
48 return phKey;
49 }
static readonly SafeNCryptProviderHandle s_microsoftSoftwareProviderHandle
Definition CngKeyLite.cs:10
static unsafe void SetExportable(SafeNCryptKeyHandle keyHandle)

References System.ReadOnlySpan< T >.Length, System.Security.Cryptography.CngKeyLite.s_microsoftSoftwareProviderHandle, System.Security.Cryptography.CngKeyLite.SetExportable(), and System.IntPtr.Zero.

Referenced by System.Security.Cryptography.ECDiffieHellmanImplementation.ECDiffieHellmanCng.ImportFullKeyBlob(), System.Security.Cryptography.ECDsaImplementation.ECDsaCng.ImportFullKeyBlob(), System.Security.Cryptography.DSAImplementation.DSACng.ImportKeyBlob(), System.Security.Cryptography.ECDiffieHellmanImplementation.ECDiffieHellmanCng.ImportKeyBlob(), System.Security.Cryptography.ECDsaImplementation.ECDsaCng.ImportKeyBlob(), System.Security.Cryptography.RSAImplementation.RSACng.ImportKeyBlob(), System.Security.Cryptography.CngPkcs8.ImportPkcs8(), and System.Security.Cryptography.CngPkcs8.ImportPkcs8().