Debian Codegraph @

external/corefx/src/System.Security.Cryptography.Pkcs/tests/EnvelopedCms/DecryptTests.KeyPersistence.cs

raw
1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4
5 using Xunit;
6
7 using System.Security.Cryptography.Pkcs.Tests;
8
9 namespace System.Security.Cryptography.Pkcs.EnvelopedCmsTests.Tests
10 {
11 public static partial class DecryptTests
12 {
13 [Theory]
14 [InlineData(Oids.Aes128)]
15 [InlineData(Oids.Aes192)]
16 [InlineData(Oids.Aes256)]
17 [InlineData(Oids.Rc2)]
18 [InlineData(Oids.Des)]
19 [InlineData(Oids.TripleDesCbc)]
20 // RC4 is not supported for CNG keys (the key provider for this cert)
21 public static void Decrypt_256_Ephemeral(string algOid)
22 {
23 byte[] content = { 1, 1, 2, 3, 5, 8, 13, 21 };
24 ContentInfo contentInfo = new ContentInfo(content);
25 TestSimpleDecrypt_RoundTrip(
26 Certificates.RSASha256KeyTransfer1.CloneAsEphemeralLoader(),
27 contentInfo,
28 algOid,
29 SubjectIdentifierType.IssuerAndSerialNumber);
30 }
31
32 [Theory]
33 [InlineData(Oids.Aes128)]
34 [InlineData(Oids.Aes192)]
35 [InlineData(Oids.Aes256)]
36 [InlineData(Oids.Rc2)]
37 [InlineData(Oids.Des)]
38 [InlineData(Oids.TripleDesCbc)]
39 // RC4 is not supported for CNG keys (the key provider for this cert)
40 [OuterLoop("Leaks key on disk if interrupted")]
41 public static void Decrypt_256_Perphemeral(string algOid)
42 {
43 byte[] content = { 1, 1, 2, 3, 5, 8, 13, 21 };
44 ContentInfo contentInfo = new ContentInfo(content);
45 TestSimpleDecrypt_RoundTrip(
46 Certificates.RSASha256KeyTransfer1.CloneAsPerphemeralLoader(),
47 contentInfo,
48 algOid,
49 SubjectIdentifierType.IssuerAndSerialNumber);
50 }
51
52 [Theory]
53 [InlineData(Oids.Aes128)]
54 [InlineData(Oids.Aes192)]
55 [InlineData(Oids.Aes256)]
56 [InlineData(Oids.Rc2)]
57 [InlineData(Oids.Des)]
58 [InlineData(Oids.TripleDesCbc)]
59 // RC4 is not supported by the CNG version of the key, so it is not supported ephemeral.
60 public static void Decrypt_Capi_Ephemeral(string algOid)
61 {
62 byte[] content = { 1, 1, 2, 3, 5, 8, 13, 21 };
63 ContentInfo contentInfo = new ContentInfo(content);
64 TestSimpleDecrypt_RoundTrip(
65 Certificates.RSAKeyTransferCapi1.CloneAsEphemeralLoader(),
66 contentInfo,
67 algOid,
68 SubjectIdentifierType.IssuerAndSerialNumber);
69 }
70
71 [Theory]
72 [InlineData(Oids.Aes128)]
73 [InlineData(Oids.Aes192)]
74 [InlineData(Oids.Aes256)]
75 [InlineData(Oids.Rc2)]
76 [InlineData(Oids.Des)]
77 [InlineData(Oids.TripleDesCbc)]
78 // RC4 works in this context.
79 [InlineData(Oids.Rc4)]
80 [OuterLoop("Leaks key on disk if interrupted")]
81 public static void Decrypt_Capi_Perphemeral(string algOid)
82 {
83 if (algOid == Oids.Rc4 && !ContentEncryptionAlgorithmTests.SupportsRc4)
84 {
85 return;
86 }
87
88 byte[] content = { 1, 1, 2, 3, 5, 8, 13, 21 };
89 ContentInfo contentInfo = new ContentInfo(content);
90 TestSimpleDecrypt_RoundTrip(
91 Certificates.RSAKeyTransferCapi1.CloneAsPerphemeralLoader(),
92 contentInfo,
93 algOid,
94 SubjectIdentifierType.IssuerAndSerialNumber);
95 }
96 }
97 }