示例#1
0
        public override ECParameters ExportParameters(bool includePrivateParameters)
        {
            ECParameters ecparams = new ECParameters();

            string curveName = GetCurveName(out string oidValue);

            byte[] blob = null;

            try
            {
                if (string.IsNullOrEmpty(curveName))
                {
                    blob = ExportFullKeyBlob(includePrivateParameters);
                    ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters);
                }
                else
                {
                    blob = ExportKeyBlob(includePrivateParameters);
                    ECCng.ExportNamedCurveParameters(ref ecparams, blob, includePrivateParameters);
                    ecparams.Curve = ECCurve.CreateFromOid(new Oid(oidValue, curveName));
                }

                return(ecparams);
            }
            finally
            {
                if (blob != null)
                {
                    Array.Clear(blob, 0, blob.Length);
                }
            }
        }
示例#2
0
            /// <summary>
            ///  Exports the key and explicit curve parameters used by the ECC object into an <see cref="ECParameters"/> object.
            /// </summary>
            /// <exception cref="CryptographicException">
            ///  if there was an issue obtaining the curve values.
            /// </exception>
            /// <exception cref="PlatformNotSupportedException">
            ///  if explicit export is not supported by this platform. Windows 10 or higher is required.
            /// </exception>
            /// <returns>The key and explicit curve parameters used by the ECC object.</returns>
            public override ECParameters ExportExplicitParameters()
            {
                ECParameters ecparams = new ECParameters();

                ECCng.ExportPrimeCurveParameters(ref ecparams, _keyBlob, includePrivateParameters: false);
                return(ecparams);
            }
        /// <summary>
        ///     Exports the key and explicit curve parameters used by the ECC object into an <see cref="ECParameters"/> object.
        /// </summary>
        /// <exception cref="CryptographicException">
        ///     if there was an issue obtaining the curve values.
        /// </exception>
        /// <exception cref="PlatformNotSupportedException">
        ///     if explicit export is not supported by this platform. Windows 10 or higher is required.
        /// </exception>
        /// <returns>The key and explicit curve parameters used by the ECC object.</returns>
        public override ECParameters ExportExplicitParameters(bool includePrivateParameters)
        {
            byte[]       blob     = ExportFullKeyBlob(includePrivateParameters);
            ECParameters ecparams = new ECParameters();

            ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters);
            return(ecparams);
        }
示例#4
0
 internal static void ExportExplicitParameters(
     CngKey key,
     bool includePrivateParameters,
     ref ECParameters ecparams)
 {
     byte[] blob = ExportFullKeyBlob(key, includePrivateParameters);
     ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters);
 }
 /// <summary>
 ///  Exports the key and explicit curve parameters used by the ECC object into an <see cref="ECParameters"/> object.
 /// </summary>
 /// <exception cref="CryptographicException">
 ///  if there was an issue obtaining the curve values.
 /// </exception>
 /// <exception cref="PlatformNotSupportedException">
 ///  if explicit export is not supported by this platform. Windows 10 or higher is required.
 /// </exception>
 /// <returns>The key and explicit curve parameters used by the ECC object.</returns>
 public override ECParameters ExportExplicitParameters()
 {
     using (CngKey key = Import())
     {
         ECParameters ecparams = default;
         byte[]       blob     = ECCng.ExportFullKeyBlob(key, includePrivateParameters: false);
         ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters: false);
         return(ecparams);
     }
 }
            /// <summary>
            ///  Exports the key and explicit curve parameters used by the ECC object into an <see cref="ECParameters"/> object.
            /// </summary>
            /// <exception cref="CryptographicException">
            ///  if there was an issue obtaining the curve values.
            /// </exception>
            /// <exception cref="PlatformNotSupportedException">
            ///  if explicit export is not supported by this platform. Windows 10 or higher is required.
            /// </exception>
            /// <returns>The key and explicit curve parameters used by the ECC object.</returns>
            public override ECParameters ExportExplicitParameters()
            {
                if (_keyBlob == null)
                {
                    throw new ObjectDisposedException(nameof(ECDiffieHellmanPublicKey));
                }

                ECParameters ecparams = new ECParameters();

                ECCng.ExportPrimeCurveParameters(ref ecparams, _keyBlob, includePrivateParameters: false);
                return(ecparams);
            }
示例#7
0
        public override ECParameters ExportExplicitParameters(bool includePrivateParameters)
        {
            byte[] blob = ExportFullKeyBlob(includePrivateParameters);

            try
            {
                ECParameters ecparams = new ECParameters();
                ECCng.ExportPrimeCurveParameters(ref ecparams, blob, includePrivateParameters);
                return(ecparams);
            }
            finally
            {
                Array.Clear(blob, 0, blob.Length);
            }
        }
示例#8
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 curve has a name, 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(bool includePrivateParameters)
        {
            ECParameters ecparams = new ECParameters();

            string curveName = GetCurveName(out string oidValue);

            if (string.IsNullOrEmpty(curveName))
            {
                byte[] fullKeyBlob = ExportFullKeyBlob(includePrivateParameters);
                ECCng.ExportPrimeCurveParameters(ref ecparams, fullKeyBlob, includePrivateParameters);
            }
            else
            {
                byte[] keyBlob = ExportKeyBlob(includePrivateParameters);
                ECCng.ExportNamedCurveParameters(ref ecparams, keyBlob, includePrivateParameters);
                ecparams.Curve = ECCurve.CreateFromOid(new Oid(oidValue, curveName));
            }

            return(ecparams);
        }
        /// <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);
            }
        }