コード例 #1
0
 public EcKeyCreateOptions(KeyCurveName curve, List <KeyOperations> keyOps, DateTimeOffset?notBefore, DateTimeOffset?expires, Dictionary <string, string> tags)
 {
     Curve         = curve;
     KeyOperations = keyOps;
     KeyType       = KeyType.EllipticCurve;
     NotBefore     = notBefore;
     Expires       = expires;
     Tags          = new Dictionary <string, string>(tags);
 }
コード例 #2
0
        private ECDsa Convert(bool includePrivateParameters, bool throwIfNotSupported)
        {
            if (!CurveName.HasValue)
            {
                if (throwIfNotSupported)
                {
                    throw new InvalidOperationException("missing required curve name");
                }

                return(null);
            }

            KeyCurveName curveName = CurveName.Value;

            int requiredParameterSize = curveName.KeyParameterSize;

            if (requiredParameterSize <= 0)
            {
                if (throwIfNotSupported)
                {
                    throw new InvalidOperationException($"invalid curve name: {CurveName.ToString()}");
                }

                return(null);
            }

            ECParameters ecParameters = new ECParameters
            {
                Curve = ECCurve.CreateFromOid(curveName.Oid),
                Q     = new ECPoint
                {
                    X = ForceBufferLength(nameof(X), X, requiredParameterSize),
                    Y = ForceBufferLength(nameof(Y), Y, requiredParameterSize),
                },
            };

            if (includePrivateParameters && HasPrivateKey)
            {
                ecParameters.D = ForceBufferLength(nameof(D), D, requiredParameterSize);
            }

            ECDsa ecdsa = ECDsa.Create();

            try
            {
                ecdsa.ImportParameters(ecParameters);
            }
            catch when(!throwIfNotSupported)
            {
                ecdsa.Dispose();

                return(null);
            }

            return(ecdsa);
        }
コード例 #3
0
        private void Initialize(ECDsa ecdsa, bool includePrivateParameters)
        {
            KeyType = KeyType.Ec;

            ECParameters ecParameters = ecdsa.ExportParameters(includePrivateParameters);

            CurveName = KeyCurveName.FromOid(ecParameters.Curve.Oid, ecdsa.KeySize).ToString() ?? throw new InvalidOperationException("elliptic curve name is invalid");
            D         = ecParameters.D;
            X         = ecParameters.Q.X;
            Y         = ecParameters.Q.Y;
        }
コード例 #4
0
        internal static string AsString(KeyCurveName curve)
        {
            switch (curve)
            {
            case KeyCurveName.P256:
                return("P-256");

            case KeyCurveName.P256K:
                return("P-256K");

            case KeyCurveName.P384:
                return("P-384");

            case KeyCurveName.P521:
                return("P-521");

            default:
                return(string.Empty);
            }
        }