public void TestMacProtectedMessage() { RsaKeyPairGenerator rsaKeyPairGenerator = new RsaKeyPairGenerator(); rsaKeyPairGenerator.Init(new RsaKeyGenerationParameters(BigInteger.ValueOf(65537), new SecureRandom(), 2048, 100)); AsymmetricCipherKeyPair rsaKeyPair = rsaKeyPairGenerator.GenerateKeyPair(); TestCertBuilder builder = new TestCertBuilder() { NotBefore = DateTime.UtcNow.AddDays(-1), NotAfter = DateTime.UtcNow.AddDays(1), PublicKey = rsaKeyPair.Public, SignatureAlgorithm = "Sha1WithRSAEncryption" }; builder.AddAttribute(X509Name.C, "Foo"); X509Certificate cert = builder.Build(rsaKeyPair.Private); GeneralName sender = new GeneralName(new X509Name("CN=Sender")); GeneralName recipient = new GeneralName(new X509Name("CN=Recip")); ProtectedPkiMessageBuilder msgBuilder = new ProtectedPkiMessageBuilder(sender, recipient); msgBuilder.AddCmpCertificate(cert); // // Default instance. // PKMacBuilder macFactory = new PKMacBuilder(); ProtectedPkiMessage msg = msgBuilder.Build(macFactory.Build("testpass".ToCharArray())); IsTrue(msg.Verify(macFactory, "testpass".ToCharArray())); }