/// <summary> /// ImportParameters will replace the existing key that ECDsaCng is working with by creating a /// new CngKey. If the parameters contains only Q, then only a public key will be imported. /// If the parameters also contains D, then a full key pair will be imported. /// The parameters Curve value specifies the type of the curve to import. /// </summary> /// <exception cref="CryptographicException"> /// if <paramref name="parameters" /> does not contain valid values. /// </exception> /// <exception cref="NotSupportedException"> /// if <paramref name="parameters" /> references a curve that cannot be imported. /// </exception> /// <exception cref="PlatformNotSupportedException"> /// if <paramref name="parameters" /> references a curve that is not supported by this platform. /// </exception> public override void ImportParameters(ECParameters parameters) { parameters.Validate(); ThrowIfDisposed(); ECCurve curve = parameters.Curve; bool includePrivateParameters = (parameters.D != null); if (curve.IsPrime) { byte[] ecExplicitBlob = ECCng.GetPrimeCurveBlob(ref parameters, ecdh: false); ImportFullKeyBlob(ecExplicitBlob, includePrivateParameters); } else if (curve.IsNamed) { // FriendlyName is required; an attempt was already made to default it in ECCurve if (string.IsNullOrEmpty(curve.Oid.FriendlyName)) { throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_InvalidCurveOid, curve.Oid.Value.ToString())); } byte[] ecNamedCurveBlob = ECCng.GetNamedCurveBlob(ref parameters, ecdh: false); ImportKeyBlob(ecNamedCurveBlob, curve.Oid.FriendlyName, includePrivateParameters); } else { throw new PlatformNotSupportedException(SR.Format(SR.Cryptography_CurveNotSupported, curve.CurveType.ToString())); } }