summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-09 13:46:52 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-09 13:46:52 +0700
commit43047794022f233577135285cf7a6aa6905ab65e (patch)
tree2a82f3ede3151e3eef177bda6e2988475022ecb7
parentCleanup (diff)
downloadBouncyCastle.NET-ed25519-43047794022f233577135285cf7a6aa6905ab65e.tar.xz
CmsContentInfoParser implements IDisposable
- Obsolete the Close method
-rw-r--r--crypto/src/cms/CMSContentInfoParser.cs27
-rw-r--r--crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs2
-rw-r--r--crypto/src/cms/CMSEnvelopedHelper.cs12
-rw-r--r--crypto/test/src/cms/test/EnvelopedDataStreamTest.cs151
-rw-r--r--crypto/test/src/cms/test/EnvelopedDataTest.cs278
-rw-r--r--crypto/test/src/cms/test/MiscDataStreamTest.cs43
-rw-r--r--crypto/test/src/cms/test/Rfc4134Test.cs8
-rw-r--r--crypto/test/src/cms/test/SignedDataStreamTest.cs47
8 files changed, 383 insertions, 185 deletions
diff --git a/crypto/src/cms/CMSContentInfoParser.cs b/crypto/src/cms/CMSContentInfoParser.cs
index c3bc9e736..86c7f459e 100644
--- a/crypto/src/cms/CMSContentInfoParser.cs
+++ b/crypto/src/cms/CMSContentInfoParser.cs
@@ -3,11 +3,11 @@ using System.IO;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
-using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Cms
 {
 	public class CmsContentInfoParser
+		: IDisposable
 	{
 		protected ContentInfoParser	contentInfo;
 		protected Stream data;
@@ -36,13 +36,28 @@ namespace Org.BouncyCastle.Cms
 			}
 		}
 
-		/**
-		* Close the underlying data stream.
-		* @throws IOException if the close fails.
-		*/
+		[Obsolete("Dispose instead")]
 		public void Close()
 		{
-            data.Dispose();
+            Dispose();
 		}
+
+		#region IDisposable
+
+		public void Dispose()
+		{
+			Dispose(true);
+			GC.SuppressFinalize(this);
+		}
+
+		protected virtual void Dispose(bool disposing)
+		{
+			if (disposing)
+			{
+				data.Dispose();
+			}
+		}
+
+		#endregion
 	}
 }
diff --git a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
index aafebee44..cfd3dde10 100644
--- a/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
+++ b/crypto/src/cms/CMSEnvelopedDataStreamGenerator.cs
@@ -26,7 +26,7 @@ namespace Org.BouncyCastle.Cms
 	*      MemoryStream  bOut = new MemoryStream();
 	*
 	*      Stream out = edGen.Open(
-	*                              bOut, CMSEnvelopedDataGenerator.AES128_CBC);*
+	*                              bOut, CMSEnvelopedGenerator.AES128_CBC);*
 	*      out.Write(data);
 	*
 	*      out.Close();
diff --git a/crypto/src/cms/CMSEnvelopedHelper.cs b/crypto/src/cms/CMSEnvelopedHelper.cs
index 86baa3642..888aba817 100644
--- a/crypto/src/cms/CMSEnvelopedHelper.cs
+++ b/crypto/src/cms/CMSEnvelopedHelper.cs
@@ -191,9 +191,9 @@ namespace Org.BouncyCastle.Cms
 //						else
 //						{
 //							string alg = macAlg.Algorithm.Id;
-//							if (alg.Equals(CmsEnvelopedDataGenerator.DesEde3Cbc)
-//								|| alg.Equals(CmsEnvelopedDataGenerator.IdeaCbc)
-//								|| alg.Equals(CmsEnvelopedDataGenerator.Cast5Cbc))
+//							if (alg.Equals(CmsEnvelopedGenerator.DesEde3Cbc)
+//								|| alg.Equals(CmsEnvelopedGenerator.IdeaCbc)
+//								|| alg.Equals(CmsEnvelopedGenerator.Cast5Cbc))
 //							{
 //								cipherParameters = new ParametersWithIV(cipherParameters, new byte[8]);
 //							}
@@ -269,9 +269,9 @@ namespace Org.BouncyCastle.Cms
 					else
 					{
                         string alg = this.algorithm.Algorithm.Id;
-						if (alg.Equals(CmsEnvelopedDataGenerator.DesEde3Cbc)
-							|| alg.Equals(CmsEnvelopedDataGenerator.IdeaCbc)
-							|| alg.Equals(CmsEnvelopedDataGenerator.Cast5Cbc))
+						if (alg.Equals(CmsEnvelopedGenerator.DesEde3Cbc)
+							|| alg.Equals(CmsEnvelopedGenerator.IdeaCbc)
+							|| alg.Equals(CmsEnvelopedGenerator.Cast5Cbc))
 						{
 							cipherParameters = new ParametersWithIV(cipherParameters, new byte[8]);
 						}
diff --git a/crypto/test/src/cms/test/EnvelopedDataStreamTest.cs b/crypto/test/src/cms/test/EnvelopedDataStreamTest.cs
index ddf14e9a6..365d0e671 100644
--- a/crypto/test/src/cms/test/EnvelopedDataStreamTest.cs
+++ b/crypto/test/src/cms/test/EnvelopedDataStreamTest.cs
@@ -104,7 +104,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			RecipientInformationStore recipients = ep.GetRecipientInfos();
 
-			Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -166,8 +166,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			MemoryStream bOut = new MemoryStream();
 
-			Stream outStream = edGen.Open(
-				bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Stream outStream = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 
 			for (int i = 0; i != 2000; i++)
 			{
@@ -176,7 +175,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			outStream.Close();
 
-			VerifyData(bOut.ToArray(), CmsEnvelopedDataGenerator.Aes128Cbc, data);
+			VerifyData(bOut.ToArray(), CmsEnvelopedGenerator.Aes128Cbc, data);
 
 			int unbufferedLength = bOut.ToArray().Length;
 
@@ -189,12 +188,12 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			bOut.SetLength(0);
 
-			outStream = edGen.Open(bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			outStream = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 
 			Streams.PipeAll(new MemoryStream(data, false), outStream);
 			outStream.Close();
 
-			VerifyData(bOut.ToArray(), CmsEnvelopedDataGenerator.Aes128Cbc, data);
+			VerifyData(bOut.ToArray(), CmsEnvelopedGenerator.Aes128Cbc, data);
 
 			Assert.AreEqual(unbufferedLength, bOut.ToArray().Length);
 		}
@@ -217,8 +216,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			MemoryStream  bOut = new MemoryStream();
 
-			Stream outStream = edGen.Open(
-				bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Stream outStream = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 
 			for (int i = 0; i != 2000; i++)
 			{
@@ -227,7 +225,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			outStream.Close();
 
-			VerifyData(bOut.ToArray(), CmsEnvelopedDataGenerator.Aes128Cbc, data);
+			VerifyData(bOut.ToArray(), CmsEnvelopedGenerator.Aes128Cbc, data);
 
 			int unbufferedLength = bOut.ToArray().Length;
 
@@ -242,7 +240,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			bOut.SetLength(0);
 
-			outStream = edGen.Open(bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			outStream = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 
 			for (int i = 0; i != 2000; i++)
 			{
@@ -251,7 +249,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			outStream.Close();
 
-			VerifyData(bOut.ToArray(), CmsEnvelopedDataGenerator.Aes128Cbc, data);
+			VerifyData(bOut.ToArray(), CmsEnvelopedGenerator.Aes128Cbc, data);
 
 			Assert.IsTrue(unbufferedLength < bOut.ToArray().Length);
 		}
@@ -271,8 +269,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			MemoryStream bOut = new MemoryStream();
 
-			Stream outStream = edGen.Open(
-				bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Stream outStream = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 
 			for (int i = 0; i != 2000; i++)
 			{
@@ -284,7 +281,7 @@ namespace Org.BouncyCastle.Cms.Tests
 			// convert to DER
 			byte[] derEncodedBytes = Asn1Object.FromByteArray(bOut.ToArray()).GetDerEncoded();
 
-			VerifyData(derEncodedBytes, CmsEnvelopedDataGenerator.Aes128Cbc, data);
+			VerifyData(derEncodedBytes, CmsEnvelopedGenerator.Aes128Cbc, data);
 		}
 
 		[Test]
@@ -307,7 +304,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			MemoryStream bOut = new MemoryStream();
 
-			Stream outStream = edGen.Open(bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Stream outStream = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 
 			for (int i = 0; i != data.Length; i++)
 			{
@@ -365,32 +362,28 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			MemoryStream bOut = new MemoryStream();
 
-			Stream outStream = edGen.Open(
-				bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Stream outStream = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 
 			outStream.Write(data, 0, data.Length);
 
 			outStream.Close();
 
-			CmsEnvelopedDataParser ep = new CmsEnvelopedDataParser(bOut.ToArray());
-
-			RecipientInformationStore recipients = ep.GetRecipientInfos();
-
-			Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
-
-			var c = recipients.GetRecipients();
-
-			foreach (RecipientInformation recipient in c)
+			using (var ep = new CmsEnvelopedDataParser(bOut.ToArray()))
 			{
-				Assert.AreEqual(recipient.KeyEncryptionAlgOid, PkcsObjectIdentifiers.RsaEncryption.Id);
+                RecipientInformationStore recipients = ep.GetRecipientInfos();
 
-				CmsTypedStream recData = recipient.GetContentStream(ReciKP.Private);
+                Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
-				Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
-			}
+                foreach (RecipientInformation recipient in recipients.GetRecipients())
+                {
+                    Assert.AreEqual(recipient.KeyEncryptionAlgOid, PkcsObjectIdentifiers.RsaEncryption.Id);
 
-			ep.Close();
-		}
+                    CmsTypedStream recData = recipient.GetContentStream(ReciKP.Private);
+
+                    Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
+                }
+            }
+        }
 
 		[Test]
 		public void TestAesKek()
@@ -408,30 +401,27 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			Stream outStream = edGen.Open(
 				bOut,
-				CmsEnvelopedDataGenerator.DesEde3Cbc);
+				CmsEnvelopedGenerator.DesEde3Cbc);
 			outStream.Write(data, 0, data.Length);
 
 			outStream.Close();
 
-			CmsEnvelopedDataParser ep = new CmsEnvelopedDataParser(bOut.ToArray());
-
-			RecipientInformationStore recipients = ep.GetRecipientInfos();
-
-			Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedDataGenerator.DesEde3Cbc);
-
-			var c = recipients.GetRecipients();
-
-			foreach (RecipientInformation recipient in c)
+			using (var ep = new CmsEnvelopedDataParser(bOut.ToArray()))
 			{
-				Assert.AreEqual(recipient.KeyEncryptionAlgOid, "2.16.840.1.101.3.4.1.25");
+                RecipientInformationStore recipients = ep.GetRecipientInfos();
 
-				CmsTypedStream recData = recipient.GetContentStream(kek);
+                Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedGenerator.DesEde3Cbc);
 
-				Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
-			}
+                foreach (RecipientInformation recipient in recipients.GetRecipients())
+                {
+                    Assert.AreEqual(recipient.KeyEncryptionAlgOid, "2.16.840.1.101.3.4.1.25");
 
-			ep.Close();
-		}
+                    CmsTypedStream recData = recipient.GetContentStream(kek);
+
+                    Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
+                }
+            }
+        }
 
 		[Test]
 		public void TestTwoAesKek()
@@ -452,31 +442,31 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			Stream outStream = edGen.Open(
 				bOut,
-				CmsEnvelopedDataGenerator.DesEde3Cbc);
+				CmsEnvelopedGenerator.DesEde3Cbc);
 			outStream.Write(data, 0, data.Length);
 
 			outStream.Close();
 
-			CmsEnvelopedDataParser ep = new CmsEnvelopedDataParser(bOut.ToArray());
-
-			RecipientInformationStore recipients = ep.GetRecipientInfos();
-
-			Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedDataGenerator.DesEde3Cbc);
-
-			RecipientID recSel = new RecipientID();
+			using (var ep = new CmsEnvelopedDataParser(bOut.ToArray()))
+			{
+                RecipientInformationStore recipients = ep.GetRecipientInfos();
 
-			recSel.KeyIdentifier = kekId2;
+                Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedGenerator.DesEde3Cbc);
 
-			RecipientInformation recipient = recipients.GetFirstRecipient(recSel);
+                var recSel = new RecipientID
+                {
+                    KeyIdentifier = kekId2
+                };
 
-			Assert.AreEqual(recipient.KeyEncryptionAlgOid, "2.16.840.1.101.3.4.1.25");
+                RecipientInformation recipient = recipients.GetFirstRecipient(recSel);
 
-			CmsTypedStream recData = recipient.GetContentStream(kek2);
+                Assert.AreEqual(recipient.KeyEncryptionAlgOid, "2.16.840.1.101.3.4.1.25");
 
-			Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
+                CmsTypedStream recData = recipient.GetContentStream(kek2);
 
-			ep.Close();
-		}
+                Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
+            }
+        }
 
 		[Test]
 		public void TestECKeyAgree()
@@ -490,35 +480,34 @@ namespace Org.BouncyCastle.Cms.Tests
 				OrigECKP.Private,
 				OrigECKP.Public,
 				ReciECCert,
-				CmsEnvelopedDataGenerator.Aes128Wrap);
+				CmsEnvelopedGenerator.Aes128Wrap);
 
 			MemoryStream bOut = new MemoryStream();
 
-			Stream outStr = edGen.Open(bOut, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Stream outStr = edGen.Open(bOut, CmsEnvelopedGenerator.Aes128Cbc);
 			outStr.Write(data, 0, data.Length);
 
 			outStr.Close();
 
-			CmsEnvelopedDataParser ep = new CmsEnvelopedDataParser(bOut.ToArray());
-
-			RecipientInformationStore recipients = ep.GetRecipientInfos();
-
-			Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
-
-			RecipientID recSel = new RecipientID();
+			using (var ep = new CmsEnvelopedDataParser(bOut.ToArray()))
+			{
+                RecipientInformationStore recipients = ep.GetRecipientInfos();
 
-//			recSel.SetIssuer(PrincipalUtilities.GetIssuerX509Principal(ReciECCert).GetEncoded());
-			recSel.Issuer = PrincipalUtilities.GetIssuerX509Principal(ReciECCert);
-			recSel.SerialNumber = ReciECCert.SerialNumber;
+                Assert.AreEqual(ep.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
-			RecipientInformation recipient = recipients.GetFirstRecipient(recSel);
+				var recSel = new RecipientID
+				{
+                    Issuer = PrincipalUtilities.GetIssuerX509Principal(ReciECCert),
+					SerialNumber = ReciECCert.SerialNumber
+	            };
 
-			CmsTypedStream recData = recipient.GetContentStream(ReciECKP.Private);
+                RecipientInformation recipient = recipients.GetFirstRecipient(recSel);
 
-			Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
+                CmsTypedStream recData = recipient.GetContentStream(ReciECKP.Private);
 
-			ep.Close();
-		}
+                Assert.IsTrue(Arrays.AreEqual(data, CmsTestUtil.StreamToByteArray(recData.ContentStream)));
+            }
+        }
 
 		[Test]
 		public void TestOriginatorInfo()
@@ -527,7 +516,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			env.GetRecipientInfos();
 
-			Assert.AreEqual(CmsEnvelopedDataGenerator.DesEde3Cbc, env.EncryptionAlgOid);
+			Assert.AreEqual(CmsEnvelopedGenerator.DesEde3Cbc, env.EncryptionAlgOid);
 		}
 	}
 }
diff --git a/crypto/test/src/cms/test/EnvelopedDataTest.cs b/crypto/test/src/cms/test/EnvelopedDataTest.cs
index 9df25f41e..1c5d1c953 100644
--- a/crypto/test/src/cms/test/EnvelopedDataTest.cs
+++ b/crypto/test/src/cms/test/EnvelopedDataTest.cs
@@ -4,11 +4,13 @@ using System.Text;
 
 using NUnit.Framework;
 using Org.BouncyCastle.Asn1;
+using Org.BouncyCastle.Asn1.CryptoPro;
 using Org.BouncyCastle.Asn1.Kisa;
 using Org.BouncyCastle.Asn1.Nist;
 using Org.BouncyCastle.Asn1.Ntt;
 using Org.BouncyCastle.Asn1.Oiw;
 using Org.BouncyCastle.Asn1.Pkcs;
+using Org.BouncyCastle.Asn1.Rosstandart;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Crypto.Operators;
@@ -174,6 +176,161 @@ namespace Org.BouncyCastle.Cms.Tests
 			+ "AKAECJwE0hkuKlWhgCBeKNXhojuej3org9Lt7n+wWxOhnky5V50vSpoYRfRR"
 			+ "yw==");
 
+        private static readonly byte[] gost2012_Sender_Cert = Base64.Decode(
+			"MIIETDCCA/mgAwIBAgIEB/tRdzAKBggqhQMHAQEDAjCB0TELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQ" +
+			"sdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQtdC90L3QuNC6MSgwJgYDVQQLDB/QlNC10LnRgdGC0LLRg9GO0YnQ" +
+			"uNC1INC70LjRhtCwMS0wKwYDVQQMDCTQpNC40LvQvtGB0L7QsiDQuCDQv9GD0LHQu9C40YbQuNGB0YIxJjAkBgNVBAMMHdCV" +
+			"0LLQs9C10L3RltC5INCe0L3Ro9Cz0LjQvdGKMB4XDTE3MDcxNTE0MDAwMFoXDTM3MDcxNT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uNC90YqCBAf7UXcwCgYIKoUDBwEBAwIDQQDcFDvbdfUu1087tslF70OeZgLW5QHRtPLUaldE9x1Geu2veJos9fZ7" +
+			"nqISVcd1wrf6FfADt3Tw2pQuG8mVCNUi"
+		);
+
+        private static readonly byte[] gost2012_Sender_Key = Base64.Decode(
+			"MEgCAQAwHwYIKoUDBwEBBgEwEwYHKoUDAgIkAAYIKoUDBwEBAgIEIgQgYARzlWBWAJLs64jQbYW4UEXqFN/ChtWCSHqRgivT" +
+			"8Ds="
+		);
+
+        private static readonly byte[] gost2012_Reci_Cert = Base64.Decode(
+			"MIIEMzCCA+CgAwIBAgIEe7X7RjAKBggqhQMHAQEDAjCByTELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQ" +
+			"sdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQtdC90L3QuNC6MR8wHQYDVQQLDBbQoNGD0LrQvtCy0L7QtNGB0YLQ" +
+			"stC+MRkwFwYDVQQMDBDQoNC10LTQsNC60YLQvtGAMTswOQYDVQQDDDLQn9GD0YjQutC40L0g0JDQu9C10LrRgdCw0L3QtNGA" +
+			"INCh0LXRgNCz0LXQtdCy0LjRhzAeFw0xNzA3MTUxNDAwMDBaFw0zNzA3MTUxNDAwMDBaMIHJMQswCQYDVQQGEwJSVTEgMB4G" +
+			"A1UECAwX0KEu0J/QuNGC0LXRgNCx0YPRgNCz0YoxHzAdBgNVBAoMFtCh0L7QstGA0LXQvNC10L3QvdC40LoxHzAdBgNVBAsM" +
+			"FtCg0YPQutC+0LLQvtC00YHRgtCy0L4xGTAXBgNVBAwMENCg0LXQtNCw0LrRgtC+0YAxOzA5BgNVBAMMMtCf0YPRiNC60LjQ" +
+			"vSDQkNC70LXQutGB0LDQvdC00YAg0KHQtdGA0LPQtdC10LLQuNGHMGYwHwYIKoUDBwEBAQEwEwYHKoUDAgIkAAYIKoUDBwEB" +
+			"AgIDQwAEQGQ4aJ3On0XqEt62PUfquYCAx0690AzlyE9IO8r5zkNKldvK4THC1IgBHkRzKiewquMm0YuYh76NI01uNjThOjyj" +
+			"ggGlMIIBoTAOBgNVHQ8BAf8EBAMCAf4wYwYDVR0lBFwwWgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDAwYIKwYBBQUH" +
+			"AwQGCCsGAQUFBwMFBggrBgEFBQcDBgYIKwYBBQUHAwcGCCsGAQUFBwMIBggrBgEFBQcDCTAPBgNVHRMBAf8EBTADAQH/MB0G" +
+			"A1UdDgQWBBROPw+FggywJjV9aLLSKz2Cr0BD9zCB+QYDVR0jBIHxMIHugBROPw+FggywJjV9aLLSKz2Cr0BD96GBz6SBzDCB" +
+			"yTELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQsdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQ" +
+			"tdC90L3QuNC6MR8wHQYDVQQLDBbQoNGD0LrQvtCy0L7QtNGB0YLQstC+MRkwFwYDVQQMDBDQoNC10LTQsNC60YLQvtGAMTsw" +
+			"OQYDVQQDDDLQn9GD0YjQutC40L0g0JDQu9C10LrRgdCw0L3QtNGAINCh0LXRgNCz0LXQtdCy0LjRh4IEe7X7RjAKBggqhQMH" +
+			"AQEDAgNBAJR6UhzmUlRzlbiCU8IjhrR15c2uFtcHqHaUfiO8XJ2bnOiwxADZbnqlN3Foul6QrTXa5Vu1UbA2hFobJeuDniQ="
+		);
+
+        private static readonly byte[] gost2012_Reci_Key = Base64.Decode(
+			"MEgCAQAwHwYIKoUDBwEBBgEwEwYHKoUDAgIkAAYIKoUDBwEBAgIEIgQgbtgmrFxhZLQm9H1Gx0+BAVTP6ZVLu20KcmKNzdIh" +
+			"rKc="
+		);
+
+        private static readonly byte[] gost2012_Reci_Msg = Base64.Decode(
+			"MIICBgYJKoZIhvcNAQcDoIIB9zCCAfMCAQAxggGyoYIBrgIBA6BooWYwHwYIKoUDBwEBAQEwEwYHKoUDAgIkAAYIKoUDBwEB" +
+			"AgIDQwAEQCX1cTzrw1FibcJBcI874EmVWLuTE5F+jJFofJbIoEV/hNhXh4RQX9aMB/d8Cqyd2nq/UM2prcpLVHXKqfVSDh2h" +
+			"CgQIDIhh5975RYMwKgYIKoUDBwEBBgEwHgYHKoUDAgINATATBgcqhQMCAh8BBAgMiGHn3vlFgzCCAQUwggEBMIHSMIHJMQsw" +
+			"CQYDVQQGEwJSVTEgMB4GA1UECAwX0KEu0J/QuNGC0LXRgNCx0YPRgNCz0YoxHzAdBgNVBAoMFtCh0L7QstGA0LXQvNC10L3Q" +
+			"vdC40LoxHzAdBgNVBAsMFtCg0YPQutC+0LLQvtC00YHRgtCy0L4xGTAXBgNVBAwMENCg0LXQtNCw0LrRgtC+0YAxOzA5BgNV" +
+			"BAMMMtCf0YPRiNC60LjQvSDQkNC70LXQutGB0LDQvdC00YAg0KHQtdGA0LPQtdC10LLQuNGHAgR7tftGBCowKAQgLMyx3zUe" +
+			"56F7eAKUAezilo3fxp6M/E+YkVVUDgFadfcEBHMmXJMwOAYJKoZIhvcNAQcBMB0GBiqFAwICFTATBAhJHfyezbxrUQYHKoUD" +
+			"AgIfAYAMLLM89stnSyrWGWSW"
+		);
+
+        private static readonly byte[] gost2012_512_Sender_Cert = Base64.Decode(
+			"MIIE0jCCBD6gAwIBAgIEMBwU/jAKBggqhQMHAQEDAzCB0TELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQ" +
+			"sdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQtdC90L3QuNC6MSgwJgYDVQQLDB/QlNC10LnRgdGC0LLRg9GO0YnQ" +
+			"uNC1INC70LjRhtCwMS0wKwYDVQQMDCTQpNC40LvQvtGB0L7QsiDQuCDQv9GD0LHQu9C40YbQuNGB0YIxJjAkBgNVBAMMHdCV" +
+			"0LLQs9C10L3RltC5INCe0L3Ro9Cz0LjQvdGKMB4XDTE3MDcxNTE0MDAwMFoXD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Ck0LjQu9C+0YHQvtCyINC4INC/0YPQsdC70LjRhtC40YHRgjEmMCQGA1UEAwwd0JXQstCz0LXQvdGW0Lkg0J7QvdGj" +
+			"0LPQuNC90YqCBDAcFP4wCgYIKoUDBwEBAwMDgYEAKZRx05mBwO7VIzj1FFJcHlfbHuLF+XZbFZaVfWc32R+KLxBJ0t1RuQ34" +
+			"KtjQhu8/oU2rR/pKcmyHRw3nxJy+DExdj7sWJ01uWH6vBa+nsXS8OzSIg+wb9hlrFy0wZSkQjyNMtSiNg+On1yzFeI2fxuAY" +
+			"OtIKHdqht+V+6M0g8BA="
+		);
+
+        private static readonly byte[] gost2012_512_Sender_Key = Base64.Decode(
+			"MGoCAQAwIQYIKoUDBwEBBgIwFQYJKoUDBwECAQIBBggqhQMHAQECAwRCBEDYpenYz4GDc/sIGl34Cv1T4xtWDlt7FB28ghXT" +
+			"n4MXm43IvLwW3YclZbRz7V9W5lR0XoftGJ9q3ICv/IN2F+Dr"
+		);
+
+        private static readonly byte[] gost2012_512_Reci_Cert = Base64.Decode(
+			"MIIEuTCCBCWgAwIBAgIECpLweDAKBggqhQMHAQEDAzCByTELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQ" +
+			"sdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQtdC90L3QuNC6MR8wHQYDVQQLDBbQoNGD0LrQvtCy0L7QtNGB0YLQ" +
+			"stC+MRkwFwYDVQQMDBDQoNC10LTQsNC60YLQvtGAMTswOQYDVQQDDDLQn9GD0YjQutC40L0g0JDQu9C10LrRgdCw0L3QtNGA" +
+			"INCh0LXRgNCz0LXQtdCy0LjRhzAeFw0xNzA3MTUxNDAwMDBaFw0zNzA3MTUxNDAwMDBaMIHJMQswCQYDVQQGEwJSVTEgMB4G" +
+			"A1UECAwX0KEu0J/QuNGC0LXRgNCx0YPRgNCz0YoxHzAdBgNVBAoMFtCh0L7QstGA0LXQvNC10L3QvdC40LoxHzAdBgN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gyFzJbxtk8wKEG7QmvlOPQvywke1pmCh8b1Z48OFOdmfKnTLE/D4AI/MQECUb1h" +
+			"ChUfgfrSw0LY205tqxp6aqDtc2iPI7XHQAKE+jD819zubjCBzVDOiyRXatiRsEtfXPTBvqQdisM4rSw+OQ=="
+		);
+
+        private static readonly byte[] gost2012_512_Reci_Key = Base64.Decode(
+			"MGoCAQAwIQYIKoUDBwEBBgIwFQYJKoUDBwECAQIBBggqhQMHAQECAwRCBEDbd6/MUJS1QjpkwGUCg8OtxzuxiU2qm2VDBDDN" +
+			"ZQ8/GtO12OiysmJHAXS9fpO1TRuyySw0r5r4x2g0NCWtVdQf"
+		);
+
+        private static readonly byte[] gost2012_512_Reci_Msg = Base64.Decode(
+			"MIICTAYJKoZIhvcNAQcDoIICPTCCAjkCAQAxggH4oYIB9AIBA6CBraGBqjAhBggqhQMHAQEBAjAVBgkqhQMHAQIBAgEGCCqF" +
+			"AwcBAQIDA4GEAASBgLnNMC1uA9NjhZMyIotCn+4H+iqcTv5paCYmRIuIvWZO7OvUv3u9aWK5Lb0wCH2Imbg/ffZV84xSwbNS" +
+			"T83w4IFh8u1mAnf302+uuqt62pBU3VtPOPt3RYRwEABSDuTlBP2VocXa2iP53HM09fxhS/AJ14eRK2oJ4cNpASXDH1mSoQoE" +
+			"CGGh2agBkurNMCoGCCqFAwcBAQYCMB4GByqFAwICDQEwEwYHKoUDAgIfAQQIYaHZqAGS6s0wggEFMIIBATCB0jCByTELMAkG" +
+			"A1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQsdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQtdC90L3Q" +
+			"uNC6MR8wHQYDVQQLDBbQoNGD0LrQvtCy0L7QtNGB0YLQstC+MRkwFwYDVQQMDBDQoNC10LTQsNC60YLQvtGAMTswOQYDVQQD" +
+			"DDLQn9GD0YjQutC40L0g0JDQu9C10LrRgdCw0L3QtNGAINCh0LXRgNCz0LXQtdCy0LjRhwIECpLweAQqMCgEIBEN53tKgcd9" +
+			"VW9uczUiwSM0pS/a7/vKIvTIqnIR0E5pBAQ+WRdXMDgGCSqGSIb3DQEHATAdBgYqhQMCAhUwEwQIbDvPAW4Wm0UGByqFAwIC" +
+			"HwGADFMeOJyH3t7YSNgxsA=="
+		);
+
+        private static readonly byte[] gost2012_KeyTrans_Reci_Cert = Base64.Decode(
+			"MIIEMzCCA+CgAwIBAgIEBSqgszAKBggqhQMHAQEDAjCByTELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQ" +
+			"sdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQtdC90L3QuNC6MR8wHQYDVQQLDBbQoNGD0LrQvtCy0L7QtNGB0YLQ" +
+			"stC+MRkwFwYDVQQMDBDQoNC10LTQsNC60YLQvtGAMTswOQYDVQQDDDLQn9GD0YjQutC40L0g0JDQu9C10LrRgdCw0L3QtNGA" +
+			"INCh0LXRgNCz0LXQtdCy0LjRhzAeFw0xNzA3MTYxNDAwMDBaFw0zNzA3MTYxNDAwMDBaMIHJMQswCQYDVQQGEwJSVTEgMB4G" +
+			"A1UECAwX0KEu0J/QuNGC0LXRgNCx0YPRgNCz0YoxHzAdBgNVBAoMFtCh0L7QstGA0LXQvNC10L3QvdC40LoxHzAdBgNVBAsM" +
+			"FtCg0YPQutC+0LLQvtC00YHRgtCy0L4xGTAXBgNVBAwMENCg0LXQtNCw0LrRgtC+0YAxOzA5BgNVBAMMMtCf0YPRiNC60LjQ" +
+			"vSDQkNC70LXQutGB0LDQvdC00YAg0KHQtdGA0LPQtdC10LLQuNGHMGYwHwYIKoUDBwEBAQEwEwYHKoUDAgIkAAYIKoUDBwEB" +
+			"AgIDQwAEQEG5/wUY0LkiqETYAZY6o5mrjwWQNBYbSIKghYgKzLgSv1RCuTEFXRIJQcMG0V80auKVZNty9kcvn9P0IcJpGfGj" +
+			"ggGlMIIBoTAOBgNVHQ8BAf8EBAMCAf4wYwYDVR0lBFwwWgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDAwYIKwYBBQUH" +
+			"AwQGCCsGAQUFBwMFBggrBgEFBQcDBgYIKwYBBQUHAwcGCCsGAQUFBwMIBggrBgEFBQcDCTAPBgNVHRMBAf8EBTADAQH/MB0G" +
+			"A1UdDgQWBBQJwiUIQOJNbB0Fzh6ucd3uRE9QzDCB+QYDVR0jBIHxMIHugBQJwiUIQOJNbB0Fzh6ucd3uRE9QzKGBz6SBzDCB" +
+			"yTELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf0LjRgtC10YDQsdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQ" +
+			"tdC90L3QuNC6MR8wHQYDVQQLDBbQoNGD0LrQvtCy0L7QtNGB0YLQstC+MRkwFwYDVQQMDBDQoNC10LTQsNC60YLQvtGAMTsw" +
+			"OQYDVQQDDDLQn9GD0YjQutC40L0g0JDQu9C10LrRgdCw0L3QtNGAINCh0LXRgNCz0LXQtdCy0LjRh4IEBSqgszAKBggqhQMH" +
+			"AQEDAgNBAKLmdCiVR9MWeoC+MNudXGny3l2uDBBttvhTli0gDEaQLnBFyvD+cfSLgsheoz8vwhyqD/6W3ATBMRiGjqNJjQE="
+		);
+
+        private static readonly byte[] gost2012_KeyTrans_Reci_Key = Base64.Decode(
+			"MEgCAQAwHwYIKoUDBwEBBgEwEwYHKoUDAgIkAAYIKoUDBwEBAgIEIgQgy+dPu0sLqJ/Fokomiu69lRA48HaPNkP7kmzDHOxP" +
+			"QFc="
+		);
+
+        private static readonly byte[] gost2012_KeyTrans_Msg = Base64.Decode(
+			"MIIB/gYJKoZIhvcNAQcDoIIB7zCCAesCAQAxggGqMIIBpgIBADCB0jCByTELMAkGA1UEBhMCUlUxIDAeBgNVBAgMF9ChLtCf" +
+			"0LjRgtC10YDQsdGD0YDQs9GKMR8wHQYDVQQKDBbQodC+0LLRgNC10LzQtdC90L3QuNC6MR8wHQYDVQQLDBbQoNGD0LrQvtCy" +
+			"0L7QtNGB0YLQstC+MRkwFwYDVQQMDBDQoNC10LTQsNC60YLQvtGAMTswOQYDVQQDDDLQn9GD0YjQutC40L0g0JDQu9C10LrR" +
+			"gdCw0L3QtNGAINCh0LXRgNCz0LXQtdCy0LjRhwIEBSqgszAfBggqhQMHAQEBATATBgcqhQMCAiQABggqhQMHAQECAgSBqjCB" +
+			"pzAoBCBnHA+9wEUh7KIkYlboGbtxRfrTL1oPGU3Tzaw8/khaWgQE+N56jaB7BgcqhQMCAh8BoGYwHwYIKoUDBwEBAQEwEwYH" +
+			"KoUDAgIkAAYIKoUDBwEBAgIDQwAEQMbb4wVWm1EWIIXKDseCNE6JHmS+4fNh2uB+10Isg7g8/1Wvdh66IFir6fyp8NRwwMkU" +
+			"QM0dmAfcpN6M2RSj83wECMCTi+FRlTafMDgGCSqGSIb3DQEHATAdBgYqhQMCAhUwEwQIzZlyAleTrCEGByqFAwICHwGADIO7" +
+			"l43OVnBpGM+FjQ=="
+		);
+
 		[Test]
 		public void TestKeyTrans()
 		{
@@ -185,12 +342,12 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.DesEde3Cbc);
+				CmsEnvelopedGenerator.DesEde3Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.DesEde3Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.DesEde3Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -305,12 +462,12 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
 			Assert.AreEqual(ed.EncryptionAlgOid,
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -335,12 +492,12 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
 			Assert.AreEqual(ed.EncryptionAlgOid,
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -364,12 +521,12 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
 			Assert.AreEqual(ed.EncryptionAlgOid,
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -434,12 +591,12 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
 			Assert.AreEqual(ed.EncryptionAlgOid,
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -455,15 +612,15 @@ namespace Org.BouncyCastle.Cms.Tests
 		[Test]
 		public void TestKeyTransCast5()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.Cast5Cbc,
-				new DerObjectIdentifier(CmsEnvelopedDataGenerator.Cast5Cbc),
+			TryKeyTrans(CmsEnvelopedGenerator.Cast5Cbc,
+				new DerObjectIdentifier(CmsEnvelopedGenerator.Cast5Cbc),
 				typeof(Asn1Sequence));
 		}
 
 		[Test]
 		public void TestKeyTransAes128()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.Aes128Cbc,
+			TryKeyTrans(CmsEnvelopedGenerator.Aes128Cbc,
 				NistObjectIdentifiers.IdAes128Cbc,
 				typeof(DerOctetString));
 		}
@@ -471,7 +628,7 @@ namespace Org.BouncyCastle.Cms.Tests
 		[Test]
 		public void TestKeyTransAes192()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.Aes192Cbc,
+			TryKeyTrans(CmsEnvelopedGenerator.Aes192Cbc,
 				NistObjectIdentifiers.IdAes192Cbc,
 				typeof(DerOctetString));
 		}
@@ -479,7 +636,7 @@ namespace Org.BouncyCastle.Cms.Tests
 		[Test]
 		public void TestKeyTransAes256()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.Aes256Cbc,
+			TryKeyTrans(CmsEnvelopedGenerator.Aes256Cbc,
 				NistObjectIdentifiers.IdAes256Cbc,
 				typeof(DerOctetString));
 		}
@@ -487,28 +644,28 @@ namespace Org.BouncyCastle.Cms.Tests
 		[Test]
 		public void TestKeyTransSeed()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.SeedCbc,
+			TryKeyTrans(CmsEnvelopedGenerator.SeedCbc,
 				KisaObjectIdentifiers.IdSeedCbc,
 				typeof(DerOctetString));
 		}
 
 		public void TestKeyTransCamellia128()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.Camellia128Cbc,
+			TryKeyTrans(CmsEnvelopedGenerator.Camellia128Cbc,
 				NttObjectIdentifiers.IdCamellia128Cbc,
 				typeof(DerOctetString));
 		}
 
 		public void TestKeyTransCamellia192()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.Camellia192Cbc,
+			TryKeyTrans(CmsEnvelopedGenerator.Camellia192Cbc,
 				NttObjectIdentifiers.IdCamellia192Cbc,
 				typeof(DerOctetString));
 		}
 
 		public void TestKeyTransCamellia256()
 		{
-			TryKeyTrans(CmsEnvelopedDataGenerator.Camellia256Cbc,
+			TryKeyTrans(CmsEnvelopedGenerator.Camellia256Cbc,
 				NttObjectIdentifiers.IdCamellia256Cbc,
 				typeof(DerOctetString));
 		}
@@ -561,7 +718,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.DesEde3Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.DesEde3Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -646,11 +803,11 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.DesEde3Cbc);
+				CmsEnvelopedGenerator.DesEde3Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.DesEde3Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.DesEde3Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -678,13 +835,13 @@ namespace Org.BouncyCastle.Cms.Tests
 				OrigECKP.Private,
 				OrigECKP.Public,
 				ReciECCert,
-				CmsEnvelopedDataGenerator.Aes128Wrap);
+				CmsEnvelopedGenerator.Aes128Wrap);
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
@@ -704,13 +861,13 @@ namespace Org.BouncyCastle.Cms.Tests
 				OrigECKP.Private,
 				OrigECKP.Public,
 				ReciECCert,
-				CmsEnvelopedDataGenerator.Aes128Wrap);
+				CmsEnvelopedGenerator.Aes128Wrap);
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
@@ -730,17 +887,17 @@ namespace Org.BouncyCastle.Cms.Tests
 			recipientCerts.Add(ReciECCert2);
 
 			edGen.AddKeyAgreementRecipients(
-				CmsEnvelopedDataGenerator.ECMqvSha1Kdf,
+				CmsEnvelopedGenerator.ECMqvSha1Kdf,
 				OrigECKP.Private,
 				OrigECKP.Public,
 				recipientCerts,
-				CmsEnvelopedDataGenerator.Aes128Wrap);
+				CmsEnvelopedGenerator.Aes128Wrap);
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
@@ -789,15 +946,15 @@ namespace Org.BouncyCastle.Cms.Tests
 		[Test]
 		public void TestPasswordAes256()
 		{
-			PasswordTest(CmsEnvelopedDataGenerator.Aes256Cbc);
-			PasswordUtf8Test(CmsEnvelopedDataGenerator.Aes256Cbc);
+			PasswordTest(CmsEnvelopedGenerator.Aes256Cbc);
+			PasswordUtf8Test(CmsEnvelopedGenerator.Aes256Cbc);
 		}
 
 		[Test]
 		public void TestPasswordDesEde()
 		{
-			PasswordTest(CmsEnvelopedDataGenerator.DesEde3Cbc);
-			PasswordUtf8Test(CmsEnvelopedDataGenerator.DesEde3Cbc);
+			PasswordTest(CmsEnvelopedGenerator.DesEde3Cbc);
+			PasswordUtf8Test(CmsEnvelopedGenerator.DesEde3Cbc);
 		}
 
 		[Test]
@@ -873,9 +1030,48 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			RecipientInformationStore  recipients = env.GetRecipientInfos();
 
-			Assert.AreEqual(CmsEnvelopedDataGenerator.DesEde3Cbc, env.EncryptionAlgOid);
+			Assert.AreEqual(CmsEnvelopedGenerator.DesEde3Cbc, env.EncryptionAlgOid);
 		}
 
+		//[Test]
+		//public void TestGost3410_2012_KeyAgree()
+		//{
+  //          AsymmetricKeyParameter privKey = PrivateKeyFactory.CreateKey(gost2012_Reci_Key);
+
+		//	CmsEnvelopedData ed = new CmsEnvelopedData(gost2012_Reci_Msg);
+
+		//	RecipientInformationStore recipients = ed.GetRecipientInfos();
+
+		//	Assert.AreEqual(ed.EncryptionAlgOid, CryptoProObjectIdentifiers.GostR28147Gcfb.Id);
+
+  //          var c = recipients.GetRecipients();
+
+  //          Assert.AreEqual(1, c.Count);
+
+		//	foreach (RecipientInformation recipient in c)
+		//	{
+		//		Assert.AreEqual(recipient.KeyEncryptionAlgOid,
+		//			RosstandartObjectIdentifiers.id_tc26_agreement_gost_3410_12_256.Id);
+
+  //              byte[] recData = recipient.GetContent(privKey);
+
+  //              Assert.AreEqual("Hello World!", Strings.FromByteArray(recData));
+		//	}
+
+		//	var cert = new X509CertificateParser().ReadCertificate(gost2012_Reci_Cert);
+  //          //CertificateFactory certFact = CertificateFactory.getInstance("X.509", BC);
+
+  //          //RecipientId id = new JceKeyAgreeRecipientId((X509Certificate)certFact.generateCertificate(new ByteArrayInputStream(gost2012_Reci_Cert)));
+  // //         RecipientID id = new KeyAgreeRecipentID(cert);
+
+		//	//var collection = recipients.GetRecipients(id);
+		//	//if (collection.Count != 1)
+		//	//{
+		//	//	Assert.Fail("recipients not matched using general recipient ID.");
+		//	//}
+		//	//Assert.IsTrue(collection[0] is RecipientInformation);
+		//}
+
 		private void PasswordTest(
 			string algorithm)
 		{
@@ -887,11 +1083,11 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
 			var c = recipients.GetRecipients();
 
@@ -920,11 +1116,11 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			CmsEnvelopedData ed = edGen.Generate(
 				new CmsProcessableByteArray(data),
-				CmsEnvelopedDataGenerator.Aes128Cbc);
+				CmsEnvelopedGenerator.Aes128Cbc);
 
 			RecipientInformationStore recipients = ed.GetRecipientInfos();
 
-			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.Aes128Cbc);
+			Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedGenerator.Aes128Cbc);
 
 			var c = recipients.GetRecipients();
 
diff --git a/crypto/test/src/cms/test/MiscDataStreamTest.cs b/crypto/test/src/cms/test/MiscDataStreamTest.cs
index 6e665c887..5ff1e6726 100644
--- a/crypto/test/src/cms/test/MiscDataStreamTest.cs
+++ b/crypto/test/src/cms/test/MiscDataStreamTest.cs
@@ -114,33 +114,32 @@ namespace Org.BouncyCastle.Cms.Tests
 			VerifySignatures(sp, null);
 		}
 
-		private void VerifyEncodedData(
-			MemoryStream bOut)
-		{
-			CmsSignedDataParser sp = new CmsSignedDataParser(bOut.ToArray());
-
-			sp.GetSignedContent().Drain();
+		//private void VerifyEncodedData(MemoryStream bOut)
+		//{
+		//	using (var sp = new CmsSignedDataParser(bOut.ToArray()))
+		//	{
+		//		sp.GetSignedContent().Drain();
 
-			VerifySignatures(sp);
-
-			sp.Close();
-		}
+		//		VerifySignatures(sp);
+		//	}
+		//}
 
 		private void CheckSigParseable(byte[] sig)
 		{
-			CmsSignedDataParser sp = new CmsSignedDataParser(sig);
-			sp.Version.ToString();
-			CmsTypedStream sc = sp.GetSignedContent();
-			if (sc != null)
+			using (var sp = new CmsSignedDataParser(sig))
 			{
-				sc.Drain();
-			}
-			sp.GetAttributeCertificates();
-			sp.GetCertificates();
-			sp.GetCrls();
-			sp.GetSignerInfos();
-			sp.Close();
-		}
+                sp.Version.ToString();
+                CmsTypedStream sc = sp.GetSignedContent();
+                if (sc != null)
+                {
+                    sc.Drain();
+                }
+                sp.GetAttributeCertificates();
+                sp.GetCertificates();
+                sp.GetCrls();
+                sp.GetSignerInfos();
+            }
+        }
 
 		[Test]
 		public void TestSha1WithRsa()
diff --git a/crypto/test/src/cms/test/Rfc4134Test.cs b/crypto/test/src/cms/test/Rfc4134Test.cs
index 072f0655c..fb617dd64 100644
--- a/crypto/test/src/cms/test/Rfc4134Test.cs
+++ b/crypto/test/src/cms/test/Rfc4134Test.cs
@@ -126,11 +126,11 @@ namespace Org.BouncyCastle.Cms.Tests
 			byte[] data = GetRfc4134Data("5.1.bin");
 			CmsEnvelopedData envelopedData = new CmsEnvelopedData(data);
 
-			VerifyEnvelopedData(envelopedData, CmsEnvelopedDataGenerator.DesEde3Cbc);
+			VerifyEnvelopedData(envelopedData, CmsEnvelopedGenerator.DesEde3Cbc);
 
 			CmsEnvelopedDataParser envelopedParser = new CmsEnvelopedDataParser(data);
 
-			VerifyEnvelopedData(envelopedParser, CmsEnvelopedDataGenerator.DesEde3Cbc);
+			VerifyEnvelopedData(envelopedParser, CmsEnvelopedGenerator.DesEde3Cbc);
 		}
 
 		[Test]
@@ -139,11 +139,11 @@ namespace Org.BouncyCastle.Cms.Tests
 			byte[] data = GetRfc4134Data("5.2.bin");
 			CmsEnvelopedData envelopedData = new CmsEnvelopedData(data);
 
-			VerifyEnvelopedData(envelopedData, CmsEnvelopedDataGenerator.RC2Cbc);
+			VerifyEnvelopedData(envelopedData, CmsEnvelopedGenerator.RC2Cbc);
 
 			CmsEnvelopedDataParser envelopedParser = new CmsEnvelopedDataParser(data);
 
-			VerifyEnvelopedData(envelopedParser, CmsEnvelopedDataGenerator.RC2Cbc);
+			VerifyEnvelopedData(envelopedParser, CmsEnvelopedGenerator.RC2Cbc);
 		}
 
 		private void VerifyEnvelopedData(CmsEnvelopedData envelopedData, string symAlgorithmOID)
diff --git a/crypto/test/src/cms/test/SignedDataStreamTest.cs b/crypto/test/src/cms/test/SignedDataStreamTest.cs
index 3d7892c6d..de4011b17 100644
--- a/crypto/test/src/cms/test/SignedDataStreamTest.cs
+++ b/crypto/test/src/cms/test/SignedDataStreamTest.cs
@@ -153,35 +153,34 @@ namespace Org.BouncyCastle.Cms.Tests
 			VerifySignatures(sp, null);
 		}
 
-		private void VerifyEncodedData(
-			MemoryStream bOut)
+		private void VerifyEncodedData(MemoryStream bOut)
 		{
-			CmsSignedDataParser sp = new CmsSignedDataParser(bOut.ToArray());
-
-			sp.GetSignedContent().Drain();
+            using (var sp = new CmsSignedDataParser(bOut.ToArray()))
+            {
+                sp.GetSignedContent().Drain();
 
-			VerifySignatures(sp);
-
-			sp.Close();
-		}
+                VerifySignatures(sp);
+            }
+        }
 
-	    private void CheckSigParseable(byte[] sig)
+        private void CheckSigParseable(byte[] sig)
 	    {
-	        CmsSignedDataParser sp = new CmsSignedDataParser(sig);
-	        sp.Version.ToString();
-	        CmsTypedStream sc = sp.GetSignedContent();
-	        if (sc != null)
-	        {
-	            sc.Drain();
-	        }
-	        sp.GetAttributeCertificates();
-	        sp.GetCertificates();
-	        sp.GetCrls();
-	        sp.GetSignerInfos();
-	        sp.Close();
-	    }
+            using (var sp = new CmsSignedDataParser(sig))
+            {
+                sp.Version.ToString();
+                CmsTypedStream sc = sp.GetSignedContent();
+                if (sc != null)
+                {
+                    sc.Drain();
+                }
+                sp.GetAttributeCertificates();
+                sp.GetCertificates();
+                sp.GetCrls();
+                sp.GetSignerInfos();
+            }
+        }
 
-		[Test]
+        [Test]
 		public void TestEarlyInvalidKeyException()
 		{
 			try