コード例 #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 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()
 {
     if (string.IsNullOrEmpty(_curveName))
     {
         return(ExportExplicitParameters());
     }
     else
     {
         ECParameters ecparams = new ECParameters();
         ECCng.ExportNamedCurveParameters(ref ecparams, _keyBlob, includePrivateParameters: false);
         ecparams.Curve = ECCurve.CreateFromFriendlyName(_curveName);
         return(ecparams);
     }
 }
コード例 #3
0
            /// <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()
            {
                if (_keyBlob == null)
                {
                    throw new ObjectDisposedException(nameof(ECDiffieHellmanPublicKey));
                }

                if (string.IsNullOrEmpty(_curveName))
                {
                    return(ExportExplicitParameters());
                }
                else
                {
                    ECParameters ecparams = new ECParameters();
                    ECCng.ExportNamedCurveParameters(ref ecparams, _keyBlob, includePrivateParameters: false);
                    ecparams.Curve = ECCurve.CreateFromFriendlyName(_curveName);
                    return(ecparams);
                }
            }
コード例 #4
0
ファイル: ECCng.cs プロジェクト: dox0/DotNet471RS3
        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);
            }
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
            }
        }