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

◆ Create() [3/3]

static CngKey System.Security.Cryptography.CngKey.Create ( CngAlgorithm algorithm,
string? keyName,
CngKeyCreationParameters? creationParameters )
inlinestatic

Definition at line 288 of file CngKey.cs.

289 {
290 if (algorithm == null)
291 {
292 throw new ArgumentNullException("algorithm");
293 }
294 if (creationParameters == null)
295 {
296 creationParameters = new CngKeyCreationParameters();
297 }
298 SafeNCryptProviderHandle safeNCryptProviderHandle = creationParameters.Provider.OpenStorageProvider();
299 global::Interop.NCrypt.ErrorCode errorCode = global::Interop.NCrypt.NCryptCreatePersistedKey(safeNCryptProviderHandle, out var phKey, algorithm.Algorithm, keyName, 0, creationParameters.KeyCreationOptions);
300 if (errorCode != 0)
301 {
302 throw errorCode.ToCryptographicException();
303 }
304 InitializeKeyProperties(phKey, creationParameters);
305 errorCode = global::Interop.NCrypt.NCryptFinalizeKey(phKey, 0);
306 if (errorCode != 0)
307 {
308 throw errorCode.ToCryptographicException();
309 }
310 CngKey cngKey = new CngKey(safeNCryptProviderHandle, phKey);
311 if (keyName == null)
312 {
313 cngKey.IsEphemeral = true;
314 }
315 return cngKey;
316 }
CngKey(SafeNCryptProviderHandle providerHandle, SafeNCryptKeyHandle keyHandle)
Definition CngKey.cs:209
static unsafe void InitializeKeyProperties(SafeNCryptKeyHandle keyHandle, CngKeyCreationParameters creationParameters)
Definition CngKey.cs:318

References System.Security.Cryptography.CngKey.CngKey(), System.Security.Cryptography.CngAlgorithm.Algorithm, System.Security.Cryptography.CngKey.InitializeKeyProperties(), System.Security.Cryptography.CngKeyCreationParameters.KeyCreationOptions, and System.Security.Cryptography.CngKeyCreationParameters.Provider.