private SafeNCryptSecretHandle DeriveSecretAgreementHandle(ECDiffieHellmanPublicKey otherPartyPublicKey) { if (otherPartyPublicKey == null) { throw new ArgumentNullException(nameof(otherPartyPublicKey)); } ECParameters otherPartyParameters = otherPartyPublicKey.ExportParameters(); using (ECDiffieHellmanCng otherPartyCng = (ECDiffieHellmanCng)Create(otherPartyParameters)) using (SafeNCryptKeyHandle otherPartyHandle = otherPartyCng.GetDuplicatedKeyHandle()) { string?importedKeyAlgorithmGroup = CngKeyLite.GetPropertyAsString( otherPartyHandle, CngKeyLite.KeyPropertyName.AlgorithmGroup, CngPropertyOptions.None); if (importedKeyAlgorithmGroup != BCryptNative.AlgorithmName.ECDH) { throw new ArgumentException(SR.Cryptography_ArgECDHRequiresECDHKey, nameof(otherPartyPublicKey)); } if (CngKeyLite.GetKeyLength(otherPartyHandle) != KeySize) { throw new ArgumentException(SR.Cryptography_ArgECDHKeySizeMismatch, nameof(otherPartyPublicKey)); } using (SafeNCryptKeyHandle localHandle = GetDuplicatedKeyHandle()) { return(Interop.NCrypt.DeriveSecretAgreement(localHandle, otherPartyHandle)); } } }
internal string GetAlgorithmGroup() { return(CngKeyLite.GetPropertyAsString( KeyHandle, CngKeyLite.KeyPropertyName.AlgorithmGroup, CngPropertyOptions.None)); }
private void AcceptImport(CngPkcs8.Pkcs8Response response) { SafeNCryptKeyHandle keyHandle = response.KeyHandle; _key.SetHandle( keyHandle, CngKeyLite.GetPropertyAsString( keyHandle, CngKeyLite.KeyPropertyName.Algorithm, CngPropertyOptions.None)); ForceSetKeySize(_key.KeySize); }