Example #1
0
 /// <summary>
 /// Create the CRL with signature for ECDsa.
 /// </summary>
 /// <returns>The signed CRL.</returns>
 public IX509CRL CreateForECDsa(X509Certificate2 issuerCertificate)
 {
     using (ECDsa ecdsa = issuerCertificate.GetECDsaPrivateKey())
     {
         var generator = X509SignatureGenerator.CreateForECDsa(ecdsa);
         return(CreateSignature(generator));
     }
 }
Example #2
0
        /// <inheritdoc/>
        public override X509Certificate2 CreateForECDsa()
        {
            if (m_ecdsaPublicKey != null && IssuerCAKeyCert == null)
            {
                throw new NotSupportedException("Cannot use a public key without a issuer certificate with a private key.");
            }

            if (m_ecdsaPublicKey == null && m_curve == null)
            {
                throw new NotSupportedException("Need a public key or a ECCurve to create the certificate.");
            }

            CreateDefaults();

            ECDsa key       = null;
            ECDsa publicKey = m_ecdsaPublicKey;

            if (publicKey == null)
            {
                key       = ECDsa.Create((ECCurve)m_curve);
                publicKey = key;
            }

            var request = new CertificateRequest(SubjectName, publicKey, HashAlgorithmName);

            CreateX509Extensions(request, true);

            var serialNumber = m_serialNumber.Reverse().ToArray();

            if (IssuerCAKeyCert != null)
            {
                using (ECDsa issuerKey = IssuerCAKeyCert.GetECDsaPrivateKey())
                {
                    return(request.Create(
                               IssuerCAKeyCert.SubjectName,
                               X509SignatureGenerator.CreateForECDsa(issuerKey),
                               NotBefore,
                               NotAfter,
                               serialNumber
                               ));
                }
            }
            else
            {
                return(request.Create(
                           SubjectName,
                           X509SignatureGenerator.CreateForECDsa(key),
                           NotBefore,
                           NotAfter,
                           serialNumber
                           )
                       .CopyWithPrivateKey(key));
            }
        }