public static void AddSigner_DSA_EphemeralKey() { using (DSA dsa = DSA.Create()) using (X509Certificate2 publicCertificate = Certificates.Dsa1024.GetCertificate()) using (X509Certificate2 certificateWithKey = Certificates.Dsa1024.TryGetCertificateWithPrivateKey(exportable: true)) { if (certificateWithKey == null) { return; } using (DSA privateKey = certificateWithKey.GetDSAPrivateKey()) using (DSA exportableKey = privateKey.MakeExportable()) { dsa.ImportParameters(exportableKey.ExportParameters(true)); } using (X509Certificate2 certWithEphemeralKey = publicCertificate.CopyWithPrivateKey(dsa)) { ContentInfo content = new ContentInfo(new byte[] { 1, 2, 3 }); SignedCms cms = new SignedCms(content, false); CmsSigner signer = new CmsSigner(certWithEphemeralKey) { DigestAlgorithm = new Oid(Oids.Sha1, Oids.Sha1) }; cms.ComputeSignature(signer); } } }