Exemplo n.º 1
0
        private byte[] ExportKeyBlob(bool includePrivateParameters)
        {
#if NETNATIVE
            return(null);
#else
            return(ECCng.ExportKeyBlob(Key, includePrivateParameters));
#endif //NETNATIVE
        }
        internal static ECDiffieHellmanCngPublicKey FromKey(CngKey key)
        {
            CngKeyBlobFormat format;
            string?          curveName;

            byte[] blob = ECCng.ExportKeyBlob(key, false, out format, out curveName);
            return(new ECDiffieHellmanCngPublicKey(blob, curveName, format));
        }
Exemplo n.º 3
0
        internal static ECDiffieHellmanCngPublicKey FromKey(CngKey key)
        {
            Contract.Requires(key != null && key.AlgorithmGroup == CngAlgorithmGroup.ECDiffieHellman);
            Contract.Ensures(Contract.Result <ECDiffieHellmanCngPublicKey>() != null);

            CngKeyBlobFormat format;
            string           curveName;

            byte[] blob = ECCng.ExportKeyBlob(key, false, out format, out curveName);
            return(new ECDiffieHellmanCngPublicKey(blob, curveName, format));
        }
Exemplo n.º 4
0
        internal static void ExportParameters(
            CngKey key,
            bool includePrivateParameters,
            ref ECParameters ecparams)
        {
            string curveName = key.GetCurveName();

            if (string.IsNullOrEmpty(curveName))
            {
                byte[] fullKeyBlob = ECCng.ExportFullKeyBlob(key, includePrivateParameters);
                ECCng.ExportPrimeCurveParameters(ref ecparams, fullKeyBlob, includePrivateParameters);
            }
            else
            {
                byte[] keyBlob = ECCng.ExportKeyBlob(key, includePrivateParameters);
                ECCng.ExportNamedCurveParameters(ref ecparams, keyBlob, includePrivateParameters);
                ecparams.Curve = ECCurve.CreateFromFriendlyName(curveName);
            }
        }
        /// <summary>
        ///  Exports the key used by the ECC object into an <see cref="ECParameters"/> object.
        ///  If the key was created as a named curve, the Curve property will contain named curve parameters
        ///  otherwise it will contain explicit parameters.
        /// </summary>
        /// <exception cref="CryptographicException">
        ///  if there was an issue obtaining the curve values.
        /// </exception>
        /// <returns>The key and named curve parameters used by the ECC object.</returns>
        public override ECParameters ExportParameters()
        {
            using (CngKey key = Import())
            {
                ECParameters ecparams  = default;
                string?      curveName = key.GetCurveName(out _);

                if (string.IsNullOrEmpty(curveName))
                {
                    byte[] fullKeyBlob = ECCng.ExportFullKeyBlob(key, includePrivateParameters: false);
                    ECCng.ExportPrimeCurveParameters(ref ecparams, fullKeyBlob, includePrivateParameters: false);
                }
                else
                {
                    byte[] keyBlob = ECCng.ExportKeyBlob(key, includePrivateParameters: false);
                    ECCng.ExportNamedCurveParameters(ref ecparams, keyBlob, includePrivateParameters: false);
                    ecparams.Curve = ECCurve.CreateFromFriendlyName(curveName);
                }

                return(ecparams);
            }
        }
Exemplo n.º 6
0
 private byte[] ExportKeyBlob(bool includePrivateParameters)
 {
     return(ECCng.ExportKeyBlob(Key, includePrivateParameters));
 }