43 protected override void Dispose(
bool disposing)
49 base.Dispose(disposing);
59 string blobType = (includePrivateParameters ?
"ECCFULLPRIVATEBLOB" :
"ECCFULLPUBLICBLOB");
65 private void ImportKeyBlob(
byte[] ecKeyBlob,
string curveName,
bool includePrivateParameters)
67 string blobType = (includePrivateParameters ?
"ECCPRIVATEBLOB" :
"ECCPUBLICBLOB");
75 string blobType = (includePrivateParameters ?
"ECCPRIVATEBLOB" :
"ECCPUBLICBLOB");
82 string blobType = (includePrivateParameters ?
"ECCFULLPRIVATEBLOB" :
"ECCFULLPUBLICBLOB");
108 if (otherPartyPublicKey ==
null)
117 if (otherPartyPublicKey ==
null)
123 using SafeNCryptKeyHandle safeNCryptKeyHandle = eCDiffieHellmanCng.GetDuplicatedKeyHandle();
125 if (propertyAsString !=
"ECDH")
134 return global::Interop.NCrypt.DeriveSecretAgreement(privateKey, safeNCryptKeyHandle);
180 if (otherPartyPublicKey ==
null)
184 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
189 return global::Interop.NCrypt.DeriveKeyMaterialHash(secretAgreement, hashAlgorithm.
Name, secretPrepend, secretAppend, global::Interop.NCrypt.SecretAgreementFlags.None);
194 if (otherPartyPublicKey ==
null)
198 if (
string.IsNullOrEmpty(hashAlgorithm.
Name))
203 global::Interop.NCrypt.SecretAgreementFlags flags = ((hmacKey ==
null) ? global::Interop.NCrypt.SecretAgreementFlags.UseSecretAsHmacKey : global::Interop.NCrypt.SecretAgreementFlags.None);
204 return global::Interop.NCrypt.DeriveKeyMaterialHmac(secretAgreement, hashAlgorithm.
Name, hmacKey, secretPrepend, secretAppend, flags);
209 if (otherPartyPublicKey ==
null)
213 if (prfLabel ==
null)
222 return global::Interop.NCrypt.DeriveKeyMaterialTls(secretAgreement, prfLabel, prfSeed, global::Interop.NCrypt.SecretAgreementFlags.None);
230 bool flag = parameters.D !=
null;
231 bool flag2 = parameters.Q.X !=
null && parameters.Q.Y !=
null;
236 byte[]
array =
new byte[parameters.
D.Length];
238 parameters2.Q.X =
array;
239 parameters2.Q.Y =
array;
258 byte[] array2 =
new byte[parameters.
D.Length];
260 parameters3.Q.X = array2;
261 parameters3.Q.Y = array2;
298 if (
string.IsNullOrEmpty(curveName))
326 bytesRead = bytesRead2;
335 bytesRead = bytesRead2;
344 bytesRead = bytesRead2;
349 if (response.GetAlgorithmGroup() !=
"ECDH")
359 if (pbeParameters ==
null)
368 if (pbeParameters ==
null)
382 if (pbeParameters ==
null)
392 if (pbeParameters ==
null)
411 protected override void Dispose(
bool disposing)
414 base.Dispose(disposing);
static unsafe void Clear(Array array)
static string Cryptography_CurveNotSupported
static string Cryptography_ArgECDHRequiresECDHKey
static string Format(string resourceFormat, object p1)
static string Cryptography_NotValidPublicOrPrivateKey
static string Cryptography_ArgECDHKeySizeMismatch
static string Cryptography_InvalidCurveOid
static string Cryptography_HashAlgorithmNameNullOrEmpty
static bool TryExportPkcs8KeyBlob(SafeNCryptKeyHandle keyHandle, ReadOnlySpan< char > password, int kdfCount, Span< byte > destination, out int bytesWritten)
static byte[] ExportPkcs8KeyBlob(SafeNCryptKeyHandle keyHandle, ReadOnlySpan< char > password, int kdfCount)
static unsafe SafeNCryptKeyHandle ImportKeyBlob(string blobType, ReadOnlySpan< byte > keyBlob, bool encrypted=false, ReadOnlySpan< char > password=default(ReadOnlySpan< char >))
static byte[] ExportKeyBlob(SafeNCryptKeyHandle keyHandle, string blobType)
static int GetKeyLength(SafeNCryptKeyHandle keyHandle)
static unsafe string GetPropertyAsString(SafeNCryptHandle ncryptHandle, string propertyName, CngPropertyOptions options)
static bool IsPlatformScheme(PbeParameters pbeParameters)
static unsafe Pkcs8Response ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
static byte[] ExportEncryptedPkcs8PrivateKey(AsymmetricAlgorithm key, ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters)
static Pkcs8Response ImportPkcs8PrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
static bool TryExportEncryptedPkcs8PrivateKey(AsymmetricAlgorithm key, ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
void GenerateKey(ECCurve curve)
string GetCurveName(int callerKeySizeProperty, out string oidValue)
void SetHandle(SafeNCryptKeyHandle keyHandle, string algorithmName)
SafeNCryptKeyHandle GetDuplicatedKeyHandle(int callerKeySizeProperty)
static string EcdhCurveNameToAlgorithm(string algorithm)
static unsafe byte[] GetPrimeCurveBlob(ref ECParameters parameters, bool ecdh)
static unsafe void ExportNamedCurveParameters(ref ECParameters ecParams, byte[] ecBlob, bool includePrivateParameters)
static unsafe byte[] GetNamedCurveBlob(ref ECParameters parameters, bool ecdh)
static unsafe void ExportPrimeCurveParameters(ref ECParameters ecParams, byte[] ecBlob, bool includePrivateParameters)
override ECParameters ExportParameters()
override void Dispose(bool disposing)
override ECParameters ExportExplicitParameters()
override string ToXmlString()
ECDiffieHellmanCngPublicKey(byte[] keyBlob, string curveName)
void ImportFullKeyBlob(byte[] ecfullKeyBlob, bool includePrivateParameters)
override void GenerateKey(ECCurve curve)
ECDiffieHellmanCng(ECCurve curve)
void ImportKeyBlob(byte[] ecKeyBlob, string curveName, bool includePrivateParameters)
SafeNCryptKeyHandle GetDuplicatedKeyHandle()
override void ImportPkcs8PrivateKey(ReadOnlySpan< byte > source, out int bytesRead)
override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters)
byte[] ExportFullKeyBlob(bool includePrivateParameters)
override void Dispose(bool disposing)
ECDiffieHellmanCng(int keySize)
byte[] ExportKeyBlob(bool includePrivateParameters)
SafeNCryptSecretHandle DeriveSecretAgreementHandle(ECDiffieHellmanPublicKey otherPartyPublicKey)
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, ReadOnlySpan< byte > source, out int bytesRead)
override byte[] DeriveKeyTls(ECDiffieHellmanPublicKey otherPartyPublicKey, byte[] prfLabel, byte[] prfSeed)
string GetCurveName(out string oidValue)
override byte[] DeriveKeyFromHash(ECDiffieHellmanPublicKey otherPartyPublicKey, HashAlgorithmName hashAlgorithm, byte[] secretPrepend, byte[] secretAppend)
override byte[] DeriveKeyMaterial(ECDiffieHellmanPublicKey otherPartyPublicKey)
override byte[] ExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters)
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< byte > passwordBytes, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
override void ImportParameters(ECParameters parameters)
override void ImportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, ReadOnlySpan< byte > source, out int bytesRead)
void AcceptImport(CngPkcs8.Pkcs8Response response)
override ECDiffieHellmanPublicKey PublicKey
override ECParameters ExportExplicitParameters(bool includePrivateParameters)
override bool TryExportEncryptedPkcs8PrivateKey(ReadOnlySpan< char > password, PbeParameters pbeParameters, Span< byte > destination, out int bytesWritten)
bool TryExportEncryptedPkcs8(ReadOnlySpan< char > pkcs8Password, int kdfCount, Span< byte > destination, out int bytesWritten)
void ForceSetKeySize(int newKeySize)
void ProcessPkcs8Response(CngPkcs8.Pkcs8Response response)
override ECParameters ExportParameters(bool includePrivateParameters)
byte[] ExportEncryptedPkcs8(ReadOnlySpan< char > pkcs8Password, int kdfCount)
override KeySizes[] LegalKeySizes
override byte[] DeriveKeyFromHmac(ECDiffieHellmanPublicKey otherPartyPublicKey, HashAlgorithmName hashAlgorithm, byte[] hmacKey, byte[] secretPrepend, byte[] secretAppend)
virtual ECParameters ExportParameters()
static new? ECDiffieHellman Create(string algorithm)
static void ValidatePbeParameters(PbeParameters pbeParameters, ReadOnlySpan< char > password, ReadOnlySpan< byte > passwordBytes)
static ECCurve CreateFromOid(Oid curveOid)
static ECCurve CreateFromFriendlyName(string oidFriendlyName)
static HashAlgorithmName SHA256