public void TestECKeyAgree()
        {
            byte[] data = Hex.Decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

            CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

            adGen.AddKeyAgreementRecipient(CmsAuthenticatedDataGenerator.ECDHSha1Kdf, OrigECKP.Private, OrigECKP.Public, ReciECCert, CmsAuthenticatedDataGenerator.Aes128Wrap);

            CmsAuthenticatedData ad = adGen.Generate(
                new CmsProcessableByteArray(data),
                CmsAuthenticatedDataGenerator.DesEde3Cbc);

            RecipientInformationStore recipients = ad.GetRecipientInfos();

            Assert.AreEqual(CmsAuthenticatedDataGenerator.DesEde3Cbc, ad.MacAlgOid);

            ICollection c = recipients.GetRecipients();

            Assert.AreEqual(1, c.Count);

            foreach (RecipientInformation recipient in c)
            {
                byte[] recData = recipient.GetContent(ReciECKP.Private);

                Assert.IsTrue(Arrays.AreEqual(data, recData));
                Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
            }
        }
예제 #2
0
        private void passwordTest(string algorithm)
        {
            byte[] data = Hex.Decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

            CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

            adGen.AddPasswordRecipient(new Pkcs5Scheme2PbeKey("password".ToCharArray(), new byte[20], 5), algorithm);

            CmsAuthenticatedData ad = adGen.Generate(
                new CmsProcessableByteArray(data),
                CmsAuthenticatedDataGenerator.DesEde3Cbc);

            RecipientInformationStore recipients = ad.GetRecipientInfos();

            Assert.AreEqual(CmsAuthenticatedDataGenerator.DesEde3Cbc, ad.MacAlgOid);

            ICollection c = recipients.GetRecipients();

            Assert.AreEqual(1, c.Count);

            foreach (PasswordRecipientInformation recipient in c)
            {
                CmsPbeKey key = new Pkcs5Scheme2PbeKey("password".ToCharArray(), recipient.KeyDerivationAlgorithm);

                byte[] recData = recipient.GetContent(key);

                Assert.IsTrue(Arrays.AreEqual(data, recData));
                Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
            }
        }
예제 #3
0
        private void tryKekAlgorithm(KeyParameter kek, DerObjectIdentifier algOid)
        {
            byte[] data = Encoding.ASCII.GetBytes("Eric H. Echidna");

            CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

            byte[] kekId = new byte[] { 1, 2, 3, 4, 5 };

            // FIXME Will this work for macs?
            string keyAlgorithm = ParameterUtilities.GetCanonicalAlgorithmName(algOid.Id);

            adGen.AddKekRecipient(keyAlgorithm, kek, kekId);

            CmsAuthenticatedData ad = adGen.Generate(
                new CmsProcessableByteArray(data),
                CmsAuthenticatedDataGenerator.DesEde3Cbc);

            RecipientInformationStore recipients = ad.GetRecipientInfos();

            Assert.AreEqual(CmsAuthenticatedDataGenerator.DesEde3Cbc, ad.MacAlgOid);

            ICollection c = recipients.GetRecipients();

            Assert.AreEqual(1, c.Count);

            foreach (RecipientInformation recipient in c)
            {
                Assert.AreEqual(recipient.KeyEncryptionAlgOid, algOid.Id);

                byte[] recData = recipient.GetContent(kek);

                Assert.IsTrue(Arrays.AreEqual(data, recData));
                Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
            }
        }
예제 #4
0
        private void tryKeyTrans(string macAlg)
        {
            byte[] data = Encoding.ASCII.GetBytes("Eric H. Echidna");

            CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

            adGen.AddKeyTransRecipient(ReciCert);

            CmsAuthenticatedData ad = adGen.Generate(
                new CmsProcessableByteArray(data),
                macAlg);

            RecipientInformationStore recipients = ad.GetRecipientInfos();

            Assert.AreEqual(ad.MacAlgOid, macAlg);

            ICollection c = recipients.GetRecipients();

            Assert.AreEqual(1, c.Count);

            foreach (RecipientInformation recipient in c)
            {
                Assert.AreEqual(recipient.KeyEncryptionAlgOid, PkcsObjectIdentifiers.RsaEncryption.Id);

                byte[] recData = recipient.GetContent(ReciKP.Private);

                Assert.IsTrue(Arrays.AreEqual(data, recData));
                Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
            }
        }
예제 #5
0
        public void TestECKeyAgree()
        {
            byte[] data = Hex.Decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

            CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

            adGen.AddKeyAgreementRecipient(CmsAuthenticatedDataGenerator.ECDHSha1Kdf, OrigECKP.Private, OrigECKP.Public, ReciECCert, CmsAuthenticatedDataGenerator.Aes128Wrap);

            CmsAuthenticatedData ad = adGen.Generate(
                new CmsProcessableByteArray(data),
                CmsAuthenticatedDataGenerator.DesEde3Cbc);

            RecipientInformationStore recipients = ad.GetRecipientInfos();

            Assert.AreEqual(CmsAuthenticatedDataGenerator.DesEde3Cbc, ad.MacAlgOid);

            ICollection c = recipients.GetRecipients();

            Assert.AreEqual(1, c.Count);

            foreach (RecipientInformation recipient in c)
            {
                byte[] recData = recipient.GetContent(ReciECKP.Private);

                Assert.IsTrue(Arrays.AreEqual(data, recData));
                Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
            }
        }
예제 #6
0
		private void passwordTest(string algorithm)
		{
			byte[] data = Hex.Decode("504b492d4320434d5320456e76656c6f706564446174612053616d706c65");

			CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

			adGen.AddPasswordRecipient(new Pkcs5Scheme2PbeKey("password".ToCharArray(), new byte[20], 5), algorithm);
		
			CmsAuthenticatedData ad = adGen.Generate(
				new CmsProcessableByteArray(data),
				CmsAuthenticatedDataGenerator.DesEde3Cbc);

			RecipientInformationStore recipients = ad.GetRecipientInfos();

			Assert.AreEqual(CmsAuthenticatedDataGenerator.DesEde3Cbc, ad.MacAlgOid);

			ICollection c = recipients.GetRecipients();

			Assert.AreEqual(1, c.Count);

			foreach (PasswordRecipientInformation recipient in c)
			{
				CmsPbeKey key = new Pkcs5Scheme2PbeKey("password".ToCharArray(), recipient.KeyDerivationAlgorithm);

				byte[] recData = recipient.GetContent(key);

				Assert.IsTrue(Arrays.AreEqual(data, recData));
				Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
			}
		}
예제 #7
0
		private void tryKekAlgorithm(KeyParameter kek, DerObjectIdentifier algOid)
		{
			byte[] data = Encoding.ASCII.GetBytes("Eric H. Echidna");

			CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

			byte[] kekId = new byte[] { 1, 2, 3, 4, 5 };

			// FIXME Will this work for macs?
			string keyAlgorithm = ParameterUtilities.GetCanonicalAlgorithmName(algOid.Id);

			adGen.AddKekRecipient(keyAlgorithm, kek, kekId);

			CmsAuthenticatedData ad = adGen.Generate(
				new CmsProcessableByteArray(data),
				CmsAuthenticatedDataGenerator.DesEde3Cbc);

			RecipientInformationStore recipients = ad.GetRecipientInfos();

			Assert.AreEqual(CmsAuthenticatedDataGenerator.DesEde3Cbc, ad.MacAlgOid);

			ICollection c = recipients.GetRecipients();

			Assert.AreEqual(1, c.Count);

			foreach (RecipientInformation recipient in c)
			{
				Assert.AreEqual(recipient.KeyEncryptionAlgOid, algOid.Id);

				byte[] recData = recipient.GetContent(kek);

				Assert.IsTrue(Arrays.AreEqual(data, recData));
				Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
			}
		}
예제 #8
0
		private void tryKeyTrans(string macAlg)
		{
			byte[] data = Encoding.ASCII.GetBytes("Eric H. Echidna");

			CmsAuthenticatedDataGenerator adGen = new CmsAuthenticatedDataGenerator();

			adGen.AddKeyTransRecipient(ReciCert);

			CmsAuthenticatedData ad = adGen.Generate(
				new CmsProcessableByteArray(data),
				macAlg);

			RecipientInformationStore recipients = ad.GetRecipientInfos();

			Assert.AreEqual(ad.MacAlgOid, macAlg);

			ICollection c = recipients.GetRecipients();

			Assert.AreEqual(1, c.Count);

			foreach (RecipientInformation recipient in c)
			{
				Assert.AreEqual(recipient.KeyEncryptionAlgOid, PkcsObjectIdentifiers.RsaEncryption.Id);

				byte[] recData = recipient.GetContent(ReciKP.Private);

				Assert.IsTrue(Arrays.AreEqual(data, recData));
				Assert.IsTrue(Arrays.AreEqual(ad.GetMac(), recipient.GetMac()));
			}
		}