public static void ThirdPartyProvider_RSA() { using (RSA rsaOther = new RSAOther()) { HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA256; CertificateRequest request = new CertificateRequest( $"CN={nameof(ThirdPartyProvider_RSA)}", rsaOther, hashAlgorithm, RSASignaturePadding.Pkcs1); byte[] signature; byte[] data = request.SubjectName.RawData; DateTimeOffset now = DateTimeOffset.UtcNow; using (X509Certificate2 cert = request.CreateSelfSigned(now, now.AddDays(1))) { using (RSA rsa = cert.GetRSAPrivateKey()) { signature = rsa.SignData(data, hashAlgorithm, RSASignaturePadding.Pkcs1); } // RSAOther is exportable, so ensure PFX export succeeds byte[] pfxBytes = cert.Export(X509ContentType.Pkcs12, request.SubjectName.Name); Assert.InRange(pfxBytes.Length, 100, int.MaxValue); } Assert.True(rsaOther.VerifyData(data, signature, hashAlgorithm, RSASignaturePadding.Pkcs1)); } }
public static void ThirdPartyProvider_RSA() { using (RSA rsaOther = new RSAOther()) { HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA256; CertificateRequest request = new CertificateRequest( $"CN={nameof(ThirdPartyProvider_RSA)}", rsaOther, hashAlgorithm); byte[] signature; byte[] data = request.SubjectName.RawData; DateTimeOffset now = DateTimeOffset.UtcNow; using (X509Certificate2 cert = request.CreateSelfSigned(now, now.AddDays(1))) using (RSA rsa = cert.GetRSAPrivateKey()) { signature = rsa.SignData(data, hashAlgorithm, RSASignaturePadding.Pkcs1); } Assert.True(rsaOther.VerifyData(data, signature, hashAlgorithm, RSASignaturePadding.Pkcs1)); } }