[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / class / System.Security / Test / System.Security.Cryptography.Pkcs / EnvelopedCmsTest.cs
blob23fbded4d360f5c01fbb0e6712a33ab3175b3cec
1 //
2 // EnvelopedCmsTest.cs - NUnit tests for EnvelopedCms
3 //
4 // Author:
5 // Sebastien Pouliot <sebastien@ximian.com>
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using NUnit.Framework;
33 using System;
34 using System.Collections;
35 using System.IO;
36 using System.Security.Cryptography;
37 using System.Security.Cryptography.Pkcs;
38 using System.Security.Cryptography.X509Certificates;
40 namespace MonoTests.System.Security.Cryptography.Pkcs {
42 [TestFixture]
43 public class EnvelopedCmsTest {
45 static byte[] asnNull = { 0x05, 0x00 };
46 static string tdesOid = "1.2.840.113549.3.7";
47 static string tdesName = "3des";
48 static string p7DataOid = "1.2.840.113549.1.7.1";
49 static string p7DataName = "PKCS 7 Data";
51 static public byte [] farscape_p12_pfx = {
52 0x30, 0x82, 0x07, 0x17, 0x02, 0x01, 0x03, 0x30, 0x82, 0x06, 0xD3, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x06, 0xC4, 0x04, 0x82, 0x06, 0xC0, 0x30, 0x82, 0x06, 0xBC, 0x30, 0x82, 0x03, 0xCD, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0xA0, 0x82, 0x03, 0xBE, 0x04, 0x82, 0x03, 0xBA, 0x30, 0x82, 0x03, 0xB6, 0x30, 0x82, 0x03, 0xB2, 0x06, 0x0B, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x0A, 0x01, 0x02, 0xA0, 0x82, 0x02, 0xB6, 0x30, 0x82, 0x02, 0xB2, 0x30, 0x1C, 0x06, 0x0A, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x01, 0x03, 0x30,
53 0x0E, 0x04, 0x08, 0x86, 0x2A, 0xA9, 0x71, 0x6D, 0xA4, 0xB8, 0x2D, 0x02, 0x02, 0x07, 0xD0, 0x04, 0x82, 0x02, 0x90, 0x90, 0x14, 0xB5, 0xF0, 0xB6, 0x86, 0x56, 0xCB, 0xFA, 0x63, 0xAD, 0x9F, 0x5A, 0x59, 0x6C, 0xAD, 0x00, 0x3C, 0x37, 0x8A, 0xC3, 0x88, 0x58, 0x8B, 0xD7, 0x48, 0x53, 0x7A, 0xC8, 0x5B, 0x0D, 0x98, 0xDD, 0x8B, 0xB3, 0xEC, 0x4C, 0xAC, 0x61, 0x18, 0xE3, 0x5E, 0x47, 0xAD, 0xC7, 0x92, 0xBC, 0xD3, 0x00, 0x07, 0xFF, 0x1A, 0x68, 0x74, 0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x9E, 0x2B, 0xE7, 0xDB, 0x7D, 0x54, 0xE1, 0xDB, 0x1E, 0xD3, 0x8F, 0xB5, 0x19, 0x4B, 0xB2, 0x16, 0xDB, 0xCF, 0xEC, 0x88, 0x0B, 0x6C, 0x3C, 0xE4, 0xF2, 0xC4, 0xFF, 0x4D, 0x3E, 0x53, 0x52, 0x3A, 0x81, 0x0B, 0x6E, 0xAC, 0x95, 0xEA, 0x5A, 0x6E, 0x4D, 0x83, 0x23, 0x82, 0xC9, 0x90, 0x02, 0x74, 0x10, 0x2A, 0x6C, 0xFB, 0x97, 0x4F, 0x5F, 0x70, 0x8E, 0xF0, 0xB9, 0x31, 0x81, 0xE8, 0x30, 0x0D, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x11, 0x02, 0x31, 0x00, 0x30, 0x13, 0x06, 0x09, 0x2A, 0x86, 0x48,
60 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x15, 0x31, 0x06, 0x04, 0x04, 0x01, 0x00, 0x00, 0x00, 0x30, 0x57, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x14, 0x31, 0x4A, 0x1E, 0x48, 0x00, 0x64, 0x00, 0x64, 0x00, 0x62, 0x00, 0x30, 0x00, 0x65, 0x00, 0x64, 0x00, 0x31, 0x00, 0x64, 0x00, 0x2D, 0x00, 0x32, 0x00, 0x36, 0x00, 0x30, 0x00, 0x34, 0x00, 0x2D, 0x00, 0x34, 0x00, 0x32, 0x00, 0x35, 0x00, 0x66, 0x00, 0x2D, 0x00, 0x38, 0x00, 0x31, 0x00, 0x35, 0x00, 0x66, 0x00, 0x2D, 0x00, 0x34, 0x00, 0x39, 0x00, 0x35, 0x00, 0x61, 0x00, 0x37, 0x00, 0x64, 0x00, 0x65, 0x00, 0x65, 0x00, 0x37, 0x00, 0x61, 0x00,
61 0x64, 0x00, 0x30, 0x30, 0x69, 0x06, 0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x82, 0x37, 0x11, 0x01, 0x31, 0x5C, 0x1E, 0x5A, 0x00, 0x4D, 0x00, 0x69, 0x00, 0x63, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x73, 0x00, 0x6F, 0x00, 0x66, 0x00, 0x74, 0x00, 0x20, 0x00, 0x52, 0x00, 0x53, 0x00, 0x41, 0x00, 0x20, 0x00, 0x53, 0x00, 0x43, 0x00, 0x68, 0x00, 0x61, 0x00, 0x6E, 0x00, 0x6E, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x20, 0x00, 0x43, 0x00, 0x72, 0x00, 0x79, 0x00, 0x70, 0x00, 0x74, 0x00, 0x6F, 0x00, 0x67, 0x00, 0x72, 0x00, 0x61, 0x00, 0x70, 0x00, 0x68, 0x00, 0x69, 0x00, 0x63, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6F,
62 0x00, 0x76, 0x00, 0x69, 0x00, 0x64, 0x00, 0x65, 0x00, 0x72, 0x30, 0x82, 0x02, 0xE7, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x06, 0xA0, 0x82, 0x02, 0xD8, 0x30, 0x82, 0x02, 0xD4, 0x02, 0x01, 0x00, 0x30, 0x82, 0x02, 0xCD, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x1C, 0x06, 0x0A, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x0C, 0x01, 0x06, 0x30, 0x0E, 0x04, 0x08, 0x0B, 0x02, 0xBA, 0x83, 0x5D, 0x71, 0x1D, 0xBD, 0x02, 0x02, 0x07, 0xD0, 0x80, 0x82, 0x02, 0xA0, 0x52, 0xD1, 0x51, 0x2A, 0xD1, 0x6D, 0x7E, 0xB0, 0x0A, 0x62, 0x6C, 0x0B, 0xE6, 0x6C, 0x72,
63 0x65, 0x3F, 0x89, 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xA1, 0x03, 0xEE, 0x06, 0x5C, 0x6C, 0x3F, 0x6F, 0x37, 0x3E, 0xCE, 0x9B, 0x26, 0x89, 0x4E, 0xDD, 0x9E, 0x57, 0x72, 0xB7, 0xD7, 0xE6, 0x25, 0xB8, 0xDA, 0x91, 0x11, 0xB2, 0xB6, 0x89, 0x18, 0x42, 0xDF, 0xA6, 0x1E, 0xB5, 0x13, 0x1D, 0x90, 0x21, 0x48, 0x75, 0x58, 0x0C, 0x0A, 0x22, 0xC2, 0x07, 0x12, 0x9B, 0x73, 0x6E,
69 0x0F, 0xCE, 0x10, 0x28, 0x3D, 0x2A, 0x45, 0x64, 0x60, 0xE3, 0xB7, 0xE1, 0x76, 0x90, 0xEC, 0x5B, 0xC6, 0xA1, 0xF0, 0xC4, 0xE8, 0x12, 0xD9, 0xC6, 0x22, 0x80, 0xB5, 0x30, 0xE5, 0x17, 0xAE, 0x05, 0x96, 0xBB, 0x4E, 0xBB, 0x33, 0xBB, 0xB0, 0x63, 0x29, 0x74, 0x11, 0x06, 0x23, 0x36, 0xB4, 0xA1, 0x25, 0xD5, 0x2A, 0xF3, 0x90, 0x38, 0x18, 0x02, 0x62, 0x30, 0x3B, 0x30, 0x1F, 0x30, 0x07, 0x06, 0x05, 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x04, 0x14, 0xDC, 0x3A, 0xAB, 0x36, 0xD7, 0x3E, 0xF4, 0x6C, 0x52, 0xC9, 0x89, 0x37, 0xFE, 0x71, 0x71, 0x83, 0xC6, 0x09, 0x88, 0xDD, 0x04, 0x14, 0xF5, 0x76, 0xC2, 0xCC, 0xB9, 0xE5,
70 0xF5, 0x28, 0xA3, 0x2D, 0x55, 0xDC, 0xDE, 0x3B, 0xCF, 0x53, 0xEE, 0x4B, 0x8F, 0x6F, 0x02, 0x02, 0x07, 0xD0 };
72 private void DefaultProperties (EnvelopedCms ep, int contentLength, int version)
74 Assert.AreEqual (0, ep.Certificates.Count, "Certificates");
75 Assert.AreEqual (0, ep.ContentEncryptionAlgorithm.KeyLength, "ContentEncryptionAlgorithm.KeyLength");
76 Assert.AreEqual (tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName, "ContentEncryptionAlgorithm.Oid.FriendlyName");
77 Assert.AreEqual (tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value, "ContentEncryptionAlgorithm.Oid.Value");
78 Assert.AreEqual (0, ep.ContentEncryptionAlgorithm.Parameters.Length, "ContentEncryptionAlgorithm.Parameters");
79 Assert.AreEqual (p7DataName, ep.ContentInfo.ContentType.FriendlyName, "ContentInfo.ContentType.FriendlyName");
80 Assert.AreEqual (p7DataOid, ep.ContentInfo.ContentType.Value, "ContentInfo.ContentType.Value");
81 Assert.AreEqual (contentLength, ep.ContentInfo.Content.Length, "ContentInfo.Content");
82 Assert.AreEqual (0, ep.RecipientInfos.Count, "RecipientInfos");
83 Assert.AreEqual (0, ep.UnprotectedAttributes.Count, "UnprotectedAttributes");
84 Assert.AreEqual (version, ep.Version, "Version");
87 private X509Certificate2 GetCertificate (bool includePrivateKey)
89 return new X509Certificate2 (farscape_p12_pfx, "farscape");
92 [Test]
93 public void ConstructorEmpty ()
95 EnvelopedCms ep = new EnvelopedCms ();
96 DefaultProperties (ep, 0, 0);
99 [Test]
100 public void ConstructorContentInfo ()
102 ContentInfo ci = new ContentInfo (asnNull);
103 EnvelopedCms ep = new EnvelopedCms (ci);
104 DefaultProperties (ep, asnNull.Length, 0);
107 [Test]
108 [ExpectedException (typeof (ArgumentNullException))]
109 public void ConstructorContentInfoNull ()
111 EnvelopedCms ep = new EnvelopedCms (null);
114 [Test]
115 public void ConstructorContentInfoAlgorithmIdentifier ()
117 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
118 ContentInfo ci = new ContentInfo (asnNull);
119 EnvelopedCms ep = new EnvelopedCms (ci, ai);
120 DefaultProperties (ep, 2, 0);
123 [Test]
124 [ExpectedException (typeof (ArgumentNullException))]
125 public void ConstructorContentInfoNullAlgorithmIdentifier ()
127 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
128 EnvelopedCms ep = new EnvelopedCms (null, ai);
131 [Test]
132 [ExpectedException (typeof (ArgumentNullException))]
133 public void ConstructorContentInfoAlgorithmIdentifierNull ()
135 ContentInfo ci = new ContentInfo (asnNull);
136 EnvelopedCms ep = new EnvelopedCms (ci, null);
139 [Test]
140 public void ConstructorSubjectIdentifierTypeIssuerAndSerialNumberContentInfoAlgorithmIdentifier ()
142 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
143 ContentInfo ci = new ContentInfo (asnNull);
144 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci, ai);
145 DefaultProperties (ep, 2, 0);
148 [Test]
149 public void ConstructorSubjectIdentifierTypeSubjectKeyIdentifierContentInfoAlgorithmIdentifier ()
151 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
152 ContentInfo ci = new ContentInfo (asnNull);
153 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.SubjectKeyIdentifier, ci, ai);
154 DefaultProperties (ep, 2, 2);
157 [Test]
158 public void ConstructorSubjectIdentifierTypeUnknownContentInfoAlgorithmIdentifier ()
160 AlgorithmIdentifier ai = new AlgorithmIdentifier ();
161 ContentInfo ci = new ContentInfo (asnNull);
162 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.Unknown, ci, ai);
163 DefaultProperties (ep, 2, 0);
166 [Test]
167 public void ConstructorSubjectIdentifierTypeIssuerAndSerialNumberContentInfo ()
169 ContentInfo ci = new ContentInfo (asnNull);
170 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
171 DefaultProperties (ep, 2, 0);
174 [Test]
175 public void ConstructorSubjectIdentifierTypeSubjectKeyIdentifierContentInfo ()
177 ContentInfo ci = new ContentInfo (asnNull);
178 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.SubjectKeyIdentifier, ci);
179 DefaultProperties (ep, 2, 2);
182 [Test]
183 public void ConstructorSubjectIdentifierTypeUnknownContentInfo ()
185 ContentInfo ci = new ContentInfo (asnNull);
186 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.Unknown, ci);
187 DefaultProperties (ep, 2, 0);
190 [Test]
191 [Category ("NotWorking")]
192 public void Decode ()
194 byte[] encoded = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x0D, 0xB7, 0xD8, 0x10, 0x84, 0x42, 0x26, 0x71, 0xB3, 0x97, 0xB5, 0x00, 0x97, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x81, 0x80, 0xCA, 0x4B, 0x97, 0x9C, 0xAB, 0x79, 0xC6, 0xDF, 0x6A, 0x27, 0xC7, 0x24, 0xC4, 0x5E, 0x3B, 0x31, 0xAD, 0xBC, 0x25, 0xE6, 0x38, 0x5E, 0x79, 0x26, 0x0E, 0x68, 0x46, 0x1D, 0x21, 0x81, 0x38, 0x92, 0xEC, 0xCB, 0x7C, 0x91, 0xD6, 0x09, 0x38, 0x91, 0xCE, 0x50, 0x5B, 0x70, 0x31, 0xB0, 0x9F, 0xFC, 0xE2, 0xEE, 0x45, 0xBC, 0x4B, 0xF8, 0x9A, 0xD9, 0xEE, 0xE7, 0x4A, 0x3D, 0xCD, 0x8D, 0xFF, 0x10, 0xAB, 0xC8, 0x19, 0x05, 0x54, 0x5E, 0x40, 0x7A, 0xBE, 0x2B, 0xD7, 0x22, 0x97, 0xF3, 0x23, 0xAF, 0x50, 0xF5, 0xEB, 0x43, 0x06, 0xC3, 0xFB, 0x17, 0xCA, 0xBD, 0xAD, 0x28, 0xD8, 0x10, 0x0F, 0x61, 0xCE, 0xF8, 0x25, 0x70, 0xF6, 0xC8, 0x1E, 0x7F, 0x82, 0xE5, 0x94, 0xEB, 0x11, 0xBF, 0xB8, 0x6F, 0xEE, 0x79, 0xCD, 0x63, 0xDD, 0x59, 0x8D, 0x25, 0x0E, 0x78, 0x55, 0xCE, 0x21, 0xBA, 0x13, 0x6B, 0x30, 0x2B, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01, 0x30, 0x14, 0x06, 0x08, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07, 0x04, 0x08, 0x8C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
195 EnvelopedCms ep = new EnvelopedCms ();
196 ep.Decode (encoded);
197 // properties
198 Assert.AreEqual (0, ep.Certificates.Count, "Certificates");
199 Assert.AreEqual (192, ep.ContentEncryptionAlgorithm.KeyLength, "ContentEncryptionAlgorithm.KeyLength");
200 Assert.AreEqual (tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName, "ContentEncryptionAlgorithm.Oid.FriendlyName");
201 Assert.AreEqual (tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value, "ContentEncryptionAlgorithm.Oid.Value");
202 Assert.AreEqual (16, ep.ContentEncryptionAlgorithm.Parameters.Length, "ContentEncryptionAlgorithm.Parameters");
203 Assert.AreEqual (p7DataName, ep.ContentInfo.ContentType.FriendlyName, "ContentInfo.ContentType.FriendlyName");
204 Assert.AreEqual (p7DataOid, ep.ContentInfo.ContentType.Value, "ContentInfo.ContentType.Value");
205 Assert.AreEqual (14, ep.ContentInfo.Content.Length, "ContentInfo.Content");
206 Assert.AreEqual (1, ep.RecipientInfos.Count, "RecipientInfos");
207 RecipientInfo ri = ep.RecipientInfos [0];
208 Assert.IsTrue ((ri is KeyTransRecipientInfo), "RecipientInfos is KeyTransRecipientInfo");
209 Assert.AreEqual (0, ep.UnprotectedAttributes.Count, "UnprotectedAttributes");
210 Assert.AreEqual (0, ep.Version, "Version");
213 [Test]
214 [ExpectedException (typeof (ArgumentNullException))]
215 public void DecodeNull ()
217 EnvelopedCms ep = new EnvelopedCms ();
218 ep.Decode (null);
221 [Test]
222 [ExpectedException (typeof (InvalidOperationException))]
223 public void EncodeEmpty ()
225 EnvelopedCms ep = new EnvelopedCms ();
226 byte[] encoded = ep.Encode ();
229 [Test]
230 [Category ("NotWorking")]
231 public void Decrypt ()
233 byte[] encoded = { 0x30, 0x82, 0x01, 0x1C, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03, 0xA0, 0x82, 0x01, 0x0D, 0x30, 0x82, 0x01, 0x09, 0x02, 0x01, 0x00, 0x31, 0x81, 0xD6, 0x30, 0x81, 0xD3, 0x02, 0x01, 0x00, 0x30, 0x3C, 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1D, 0x4D, 0x6F, 0x74, 0x75, 0x73, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x69, 0x65, 0x73, 0x20, 0x69, 0x6E, 0x63, 0x2E, 0x28, 0x74, 0x65, 0x73, 0x74, 0x29, 0x02, 0x10, 0x91, 0xC4, 0x4B, 0x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C, 0x5D, 0xC9, 0x87, 0x88, 0x9C, 0x05, 0x72, 0x80, 0x08, 0x2C, 0xAF, 0x82, 0x91, 0xEC, 0xAD, 0xC5, 0xB5 };
234 EnvelopedCms ep = new EnvelopedCms ();
235 ep.Decode (encoded);
237 X509Certificate2 x509 = GetCertificate (true);
238 X509Certificate2Collection xc = new X509Certificate2Collection ();
239 xc.Add (x509);
240 ep.Decrypt (xc);
241 // properties
242 Assert.AreEqual (0, ep.Certificates.Count, "Certificates");
243 Assert.AreEqual (192, ep.ContentEncryptionAlgorithm.KeyLength, "ContentEncryptionAlgorithm.KeyLength");
244 Assert.AreEqual (tdesName, ep.ContentEncryptionAlgorithm.Oid.FriendlyName, "ContentEncryptionAlgorithm.Oid.FriendlyName");
245 Assert.AreEqual (tdesOid, ep.ContentEncryptionAlgorithm.Oid.Value, "ContentEncryptionAlgorithm.Oid.Value");
246 Assert.AreEqual (16, ep.ContentEncryptionAlgorithm.Parameters.Length, "ContentEncryptionAlgorithm.Parameters");
247 Assert.AreEqual (p7DataName, ep.ContentInfo.ContentType.FriendlyName, "ContentInfo.ContentType.FriendlyName");
248 Assert.AreEqual (p7DataOid, ep.ContentInfo.ContentType.Value, "ContentInfo.ContentType.Value");
249 Assert.AreEqual ("05-00", BitConverter.ToString (ep.ContentInfo.Content), "ContentInfo.Content");
250 Assert.AreEqual (1, ep.RecipientInfos.Count, "RecipientInfos");
251 Assert.AreEqual (0, ep.UnprotectedAttributes.Count, "UnprotectedAttributes");
252 Assert.AreEqual (0, ep.Version, "Version");
255 [Test]
256 [ExpectedException (typeof (InvalidOperationException))]
257 public void DecryptEmpty ()
259 EnvelopedCms ep = new EnvelopedCms ();
260 ep.Decrypt ();
263 [Test]
264 [ExpectedException (typeof (ArgumentNullException))]
265 public void DecryptRecipientInfoNull ()
267 EnvelopedCms ep = new EnvelopedCms ();
268 RecipientInfo ri = null; // do not confuse compiler
269 ep.Decrypt (ri);
272 [Test]
273 [ExpectedException (typeof (ArgumentNullException))]
274 public void DecryptX509CertificateExCollectionNull ()
276 EnvelopedCms ep = new EnvelopedCms ();
277 X509Certificate2Collection xec = null; // do not confuse compiler
278 ep.Decrypt (xec);
281 [Test]
282 [ExpectedException (typeof (ArgumentNullException))]
283 public void DecryptRecipientInfoX509CertificateExCollectionNull ()
285 EnvelopedCms ep = new EnvelopedCms ();
286 X509Certificate2Collection xec = new X509Certificate2Collection ();
287 ep.Decrypt (null, xec);
290 /* [Test]
291 [ExpectedException (typeof (ArgumentNullException))]
292 public void DecryptX509CertificateExCollectionNull ()
294 EnvelopedPkcs7 ep = new EnvelopedPkcs7 ();
295 RecipientInfo ri =
296 ep.Decrypt (ri, null);
299 private void RoundTrip (byte[] encoded)
301 X509Certificate2Collection xc = new X509Certificate2Collection ();
302 xc.Add (GetCertificate (true));
303 EnvelopedCms ep = new EnvelopedCms ();
304 ep.Decode (encoded);
305 ep.Decrypt (xc);
306 Assert.AreEqual ("05-00", BitConverter.ToString (ep.ContentInfo.Content), "ContentInfo.Content");
309 [Test]
310 [Category ("NotWorking")]
311 public void EncryptCmsRecipientIssuerAndSerialNumber ()
313 ContentInfo ci = new ContentInfo (asnNull);
314 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
316 X509Certificate2 x509 = GetCertificate (false);
317 CmsRecipient p7r = new CmsRecipient (SubjectIdentifierType.IssuerAndSerialNumber, x509);
318 ep.Encrypt (p7r);
319 byte[] encoded = ep.Encode ();
320 #if DEBUG
321 FileStream fs = File.OpenWrite ("EncryptCmsRecipientIssuerAndSerialNumber.der");
322 fs.Write (encoded, 0, encoded.Length);
323 fs.Close ();
324 #endif
325 RoundTrip (encoded);
328 [Test]
329 [Category ("NotWorking")]
330 public void EncryptCmsRecipientSubjectKeyIdentifier ()
332 ContentInfo ci = new ContentInfo (asnNull);
333 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
335 X509Certificate2 x509 = GetCertificate (false);
336 CmsRecipient p7r = new CmsRecipient (SubjectIdentifierType.SubjectKeyIdentifier, x509);
337 ep.Encrypt (p7r);
338 byte[] encoded = ep.Encode ();
339 #if DEBUG
340 FileStream fs = File.OpenWrite ("EncryptCmsRecipientSubjectKeyIdentifier.der");
341 fs.Write (encoded, 0, encoded.Length);
342 fs.Close ();
343 #endif
344 RoundTrip (encoded);
347 [Test]
348 [Category ("NotWorking")]
349 public void EncryptCmsRecipientUnknown ()
351 ContentInfo ci = new ContentInfo (asnNull);
352 EnvelopedCms ep = new EnvelopedCms (SubjectIdentifierType.IssuerAndSerialNumber, ci);
354 X509Certificate2 x509 = GetCertificate (false);
355 CmsRecipient p7r = new CmsRecipient (SubjectIdentifierType.Unknown, x509);
356 ep.Encrypt (p7r);
357 byte[] encoded = ep.Encode ();
358 #if DEBUG
359 FileStream fs = File.OpenWrite ("EncryptCmsRecipientUnknown.der");
360 fs.Write (encoded, 0, encoded.Length);
361 fs.Close ();
362 #endif
363 RoundTrip (encoded);
366 [Test]
367 [Category ("NotWorking")]
368 [ExpectedException (typeof (CryptographicException))]
369 public void EncryptEmpty ()
371 EnvelopedCms ep = new EnvelopedCms ();
372 ep.Encrypt ();
375 [Test]
376 [ExpectedException (typeof (ArgumentNullException))]
377 public void EnvelopedCmsRecipientNull ()
379 EnvelopedCms ep = new EnvelopedCms ();
380 CmsRecipient p7r = null; // do not confuse compiler
381 ep.Encrypt (p7r);
384 [Test]
385 [ExpectedException (typeof (ArgumentNullException))]
386 public void EnvelopedCmsRecipientCollectionNull ()
388 EnvelopedCms ep = new EnvelopedCms ();
389 CmsRecipientCollection p7rc = null; // do not confuse compiler
390 ep.Encrypt (p7rc);