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()));
            }
        }
Example #2
0
        private void TryKekAlgorithm(
            KeyParameter kek,
            DerObjectIdentifier algOid)
        {
            byte[] data = Encoding.ASCII.GetBytes("WallaWallaWashington");
            CmsEnvelopedDataGenerator edGen = new CmsEnvelopedDataGenerator();

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

            string keyAlgorithm = ParameterUtilities.GetCanonicalAlgorithmName(algOid.Id);

            edGen.AddKekRecipient(keyAlgorithm, kek, kekId);

            CmsEnvelopedData ed = edGen.Generate(
                new CmsProcessableByteArray(data),
                CmsEnvelopedDataGenerator.DesEde3Cbc);

            RecipientInformationStore recipients = ed.GetRecipientInfos();

            Assert.AreEqual(ed.EncryptionAlgOid, CmsEnvelopedDataGenerator.DesEde3Cbc);

            ArrayList c = new ArrayList(recipients.GetRecipients());

            Assert.IsTrue(c.Count > 0);

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

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

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