16 global::Interop.NCrypt.ErrorCode errorCode;
21 global::Interop.NCrypt.NCryptBuffer* ptr = stackalloc global::Interop.NCrypt.NCryptBuffer[1];
22 *ptr =
new global::Interop.NCrypt.NCryptBuffer
24 BufferType = global::Interop.NCrypt.BufferType.PkcsSecret,
25 cbBuffer = checked(2 * (password.Length + 1)),
26 pvBuffer = safeUnicodeStringHandle.DangerousGetHandle()
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;
45 throw errorCode.ToCryptographicException();
60 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptExportKey(keyHandle,
IntPtr.
Zero, blobType,
IntPtr.
Zero,
null, 0, out var pcbResult, 0);
63 throw errorCode.ToCryptographicException();
67 return Array.Empty<
byte>();
69 byte[]
array =
new byte[pcbResult];
73 throw errorCode.ToCryptographicException();
75 if (
array.Length != pcbResult)
104 global::Interop.NCrypt.NCryptBuffer* ptr = stackalloc global::Interop.NCrypt.NCryptBuffer[3];
105 global::Interop.NCrypt.PBE_PARAMS pBE_PARAMS =
default(global::Interop.NCrypt.PBE_PARAMS);
108 pBE_PARAMS.Params.cbSalt = data.
Length;
109 pBE_PARAMS.Params.iIterations = kdfCount;
110 *ptr =
new global::Interop.NCrypt.NCryptBuffer
112 BufferType = global::Interop.NCrypt.BufferType.PkcsSecret,
113 cbBuffer = checked(2 * (password.
Length + 1)),
114 pvBuffer = safeUnicodeStringHandle.DangerousGetHandle()
120 ptr[1] =
new global::Interop.NCrypt.NCryptBuffer
122 BufferType = global::Interop.NCrypt.BufferType.PkcsAlgOid,
126 ptr[2] =
new global::Interop.NCrypt.NCryptBuffer
128 BufferType = global::Interop.NCrypt.BufferType.PkcsAlgParam,
129 cbBuffer =
sizeof(global::Interop.NCrypt.PBE_PARAMS),
130 pvBuffer = (
IntPtr)(&pBE_PARAMS)
132 global::Interop.NCrypt.NCryptBufferDesc nCryptBufferDesc =
default(global::Interop.NCrypt.NCryptBufferDesc);
133 nCryptBufferDesc.cBuffers = 3;
134 nCryptBufferDesc.pBuffers = (
IntPtr)ptr;
135 nCryptBufferDesc.ulVersion = 0;
136 global::Interop.NCrypt.NCryptBufferDesc pParameterList = nCryptBufferDesc;
137 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptExportKey(keyHandle,
IntPtr.
Zero,
"PKCS8_PRIVATEKEY", ref pParameterList, ref
MemoryMarshal.GetReference(
default(
Span<byte>)), 0, out var pcbResult, 0);
140 throw errorCode.ToCryptographicException();
145 allocated =
new byte[pcbResult];
156 throw errorCode.ToCryptographicException();
160 byte[]
array =
new byte[pcbResult];
165 bytesWritten = pcbResult;
175 throw errorCode.ToCryptographicException();
179 errorCode = global::Interop.NCrypt.NCryptFinalizeKey(phKey, 0);
182 throw errorCode.ToCryptographicException();
192 throw errorCode.ToCryptographicException();
196 errorCode = global::Interop.NCrypt.NCryptFinalizeKey(phKey, 0);
199 throw errorCode.ToCryptographicException();
209 throw errorCode.ToCryptographicException();
213 SetProperty(phKey,
"ECCParameters", primeCurveParameterBlob);
214 errorCode = global::Interop.NCrypt.NCryptFinalizeKey(phKey, 0);
217 throw errorCode.ToCryptographicException();
269 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptGetProperty(ncryptHandle, propertyName,
null, 0, out var pcbResult,
options);
272 case global::Interop.NCrypt.ErrorCode.NTE_NOT_FOUND:
275 throw errorCode.ToCryptographicException();
276 case global::Interop.NCrypt.ErrorCode.ERROR_SUCCESS:
278 byte[]
array =
new byte[pcbResult];
279 fixed (
byte* pbOutput =
array)
281 errorCode = global::Interop.NCrypt.NCryptGetProperty(ncryptHandle, propertyName, pbOutput,
array.Length, out pcbResult,
options);
285 case global::Interop.NCrypt.ErrorCode.NTE_NOT_FOUND:
288 throw errorCode.ToCryptographicException();
289 case global::Interop.NCrypt.ErrorCode.ERROR_SUCCESS: