コード例 #1
0
            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));
                        }
                    }
            }
コード例 #2
0
ファイル: CngPkcs8.cs プロジェクト: shandan1/CollectionRef
 internal string GetAlgorithmGroup()
 {
     return(CngKeyLite.GetPropertyAsString(
                KeyHandle,
                CngKeyLite.KeyPropertyName.AlgorithmGroup,
                CngPropertyOptions.None));
 }
コード例 #3
0
            private void AcceptImport(CngPkcs8.Pkcs8Response response)
            {
                SafeNCryptKeyHandle keyHandle = response.KeyHandle;

                _key.SetHandle(
                    keyHandle,
                    CngKeyLite.GetPropertyAsString(
                        keyHandle,
                        CngKeyLite.KeyPropertyName.Algorithm,
                        CngPropertyOptions.None));

                ForceSetKeySize(_key.KeySize);
            }