-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathImportKeyExtTests.cs
146 lines (136 loc) · 15.3 KB
/
ImportKeyExtTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Security.Cryptography;
using Xunit;
namespace RSAExtensions.UnitTests
{
public class ImportKeyExtTests
{
[Fact]
public void ImportPkcs1PrivateKey_WithoutPEM_ShouldBeOk()
{
var rsa = RSA.Create();
rsa.ImportPrivateKey(RSAKeyType.Pkcs1, "MIIEpAIBAAKCAQEAwutJA3T4/th/PCOv7ITtx1ESBSEkTplsGiIO/CY9tevb0lxQMW9TIWGdi/0Z72Pn8c9QFG+CSo+ye2ncrgl/ubm3Rato94nQarDDsfomKLcQeMFBE6I+qLZCjYriWxgA2xVF6px3XZd4yZh37ZTFDvAWFxI3dBXt8NrNyL8FCQ1d8viY6VmpD8+qUwYKlry48xCTxOrrvev73SFrnJU3owvMFkxzXn7tTEj0Jr2wHSU9m42lGNcFuvSQgL1OdZbn20SDDGQfXMyFW+B4twLkI2ZO2s5lLXaQKbZA3Z4puGQooY/NJh8mKDtVh3+UlKl3jH3ZIbFmAhwT0LLebVmU9QIDAQABAoIBAQCXj7n7PSYriw4MJjex8n6tYAViBa4ki7l57Ie4WsfbQCVyQaN9fPGn4C5P3qMe+JEu/iNncHlgHrIKsnsMvIgbUyQFwU3iRL/RZdcU+cxYFlhxfNtsN9j++JFxW8+8Q0LPF5CA598M4C3km3CNRQOhJOAYWmrSEgct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r2+Uov07FkGB2r9j6wkr2ulqBkCnMR+1sOgvAHWDV8NOBz4iJoJDjIzp7xZrQH6YuIjMqMZQ7rdCHfflCguh78imgnCh94bxwnBbK5MeSMtN4EmsMgUHvtI4Ab6ZwR3ldJJRbbua+BFwcHV4sJLGHooK9UP0egBEySQ28cDJC4b5Msi6Iw6eSPsdnfdHeiKo1owCKK9SzGhFeO6C2e3yuRfmT+Q9CkVoYFPBkfPEK4WSIn1T6orhtCn8risoZQa/D5Q04FL44encN/6LSMYyS+nTQA05/pXkNFVaPtAC9jK4Yo6kug0sQIDAQAB");
}
[Fact]
public void ImportPkcs8PrivateKey_WithoutPEM_ShouldBeExp()
{
var rsa = RSA.Create();
Assert.Throws<FormatException>(() => rsa.ImportPrivateKey(RSAKeyType.Pkcs8,
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDvOzxVDfg1BzMyvIdA3iDISBdCr8m+wY7ccFqcna/BvWAKvnWjY3zFu0Gpy2xrQvuSLtFXzUkFJrrru7stF5IeJ11QUjiiBlpv35crOMxA7NA4d+bteQrgQhsypEoCyRs/biXLoK4RQrGUAy+X1qRPyjJHO4cFMYcWcZPgQCLy2MN31VTYkeP1k0r7UGPJBKjm/ZGCTK8WeE6nWyuqh6WXjNToea1fFWjaOMzzbjrV/d1pq9i3N7H0KXgMVp7hPm8m2CsCXmER0DqueU8DIhbKqVXg33kYakxevxo8oGM2FelU45ZW7M/dv4+KtIBVKH4h7c7/4Bs0lo8tNJ1+T4lJAgMBAAECggEBAJ0g1gazbzQ9L2aCp392pieGGikF1seA0Dl/XjSB6Z+hp8RGxnNzc89Xp9BDOUnWK/Ae6gb2YaCNiLYujskWMzW0+zg3WNUqwRm7zMlpu9Zk9HoyXq3ZE8iqAr0nZSkhN9FYomB1f/78RDCISyk6pJ93mcBpm8xQdH7MSKlA1vOTINJPcMxfMfZVjDXKoeM3cVYOkFT6+T+LEe1sM0buYyh/ovcVmnh67rEuu6oHGQJY51t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Jk/0MKC1ImlRT/ezcnOAkvp+vFtRcpuJD08pfcWg3rnW8R1mT0Ll3FG8
4ixROIGSqwKBgQCbtPiLFmMpmPS7XfXv00IEfTnjRq7M9Tt8Xntukme2tP4R1wZk
LKfUGCVw9TCKavS5anAklYPKfigOlG5k47h6MSauiotwPfXA9IVQl7kY2BbNn6N5
ZN1UWCPx9AvOqIOWE+VD9lM1fzi35MgrYLhNBETfCueP55FzS9rCP0DBVQKBgGI6
oOnMzSRbsFOGY1QqRUDREB7dKP4IasCQ8hT3+yn6h5xoW67k6PP1/EZ6zV/kaGAu
gCPJ5NZbfFop8uhaDjVMZrp/o+QoHLTXJ3ulSyqAqc/UVBiNlhI+tsFEf0qRTZC8
AKNdBGF4ve28vOqK0dHwHUO/AKO1ySzBFm8jR5QTAoGAITBswWXgtWqXl/y8o1kQ
23jXpD0XBIBzpyXzW8yHge99058W3JmqQ9NMy7xdaqwV9cnArS6dkzyrZ1ZRnCs/
OgXikoHfPBBK89vqbqTLlqYPq2z7QmfWpGs6ufq/FgSqxEk0gvIXjZ6N3PkBR0Ia
MQB0WkAHcHJ+9np4dlvPxNU=
-----END PRIVATE KEY-----", true);
}
[Fact]
public void ImportXmlPrivateKey_ShouldBeOk()
{
var rsa = RSA.Create();
rsa.ImportPrivateKey(RSAKeyType.Xml, @"<RSAKeyValue>
<Modulus>tuE1XbeCD5bS0tLnlH4mVb6odtfztJQRNDbOhTY9rWmyc6H+8+2HHF4N8vZC8tgQnUj6KYvllQAxeUDsjmLY4XbYPZP1px8xevMP/BTM+ogc5HIfuSJrawJW87fJvjDzquR4efRkNXxeNscRp1E4ZAyrq6aiJOxhQ6UgGOsRLVlbCZMNKJQTsPWOe9aO1KfvujmphdBz754YrAWbvyYplYyg1ritTmEcFH5LNYKfrdNQvOZfDFWz9G8fwV/2efNZI8zOGX4E7uRzByL+PRDud5A60FXjjbOxYOKxXE49ESsBsdWqmz2+TtmDtVbEqieof0iDkMqD9y/EAugKTR9GMQ==</Modulus>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c2rX9rKvk+NDWV0GvX33HPwF7Gf5atg66AGgn2AiibOCPXAchgw7CpKpvuyPqXeZo3oI3aFCMz3naw8EqZO9UILu0+v/SqVEPm3cnvEyCpgvay3adal2Va9WCk0tHZwS7gE7KccWZjrFP54s21HkseE0YDHEfGa/O+wAiOXoN0IHmY2ljP2GvvY7QnAGILCwZkqSsvR/yQ==</D>
</RSAKeyValue>");
}
[Fact]
public void ImportXmlPrivateKey_ShouldBeExp()
{
var rsa = RSA.Create();
Assert.Throws<Exception>(() => rsa.ImportPrivateKey(RSAKeyType.Xml,
@"<RSAKeyValue>
<Modulus>tuE1XbeCD5bS0tLnlH4mVb6odtfztJQRNDbOhTY9rWmyc6H+8+2HHF4N8vZC8tgQnUj6KYvllQAxeUDsjmLY4XbYPZP1px8xevMP/BTM+ogc5HIfuSJrawJW87fJvjDzquR4efRkNXxeNscRp1E4ZAyrq6aiJOxhQ6UgGOsRLVlbCZMNKJQTsPWOe9aO1KfvujmphdBz754YrAWbvyYplYyg1ritTmEcFH5LNYKfrdNQvOZfDFWz9G8fwV/2efNZI8zOGX4E7uRzByL+PRDud5A60FXjjbOxYOKxXE49ESsBsdWqmz2+TtmDtVbEqieof0iDkMqD9y/EAugKTR9GMQ==</Modulus>
<P>xlo0Vx6rGZQdlrtGheFNKk/VdJWH2hbLgggDhOHwYEFYIOX9t2vIAFApDeXD/7zHBYanenLfCCoNtYOEgyXT2Z24YFsh1X70H00+2bOmw2JQDPJL6OkEDJakiRV/oxEDCZilQVZvmAEPEGeLrZPErK0Rbcfp9mgOpu1EQH9RZSs=</P>
<Q>7AfPVoPwcsG7+/4v2+ZXBIiW6bb0auqksYkbUaN3BRsoGGypD8HAj3HKG/BzAOnRAnE+Hhw1ND8sO7M7ghCcSQsfu40wvjS9LZbabt4PmQE29FQt2OrODEysQy+lPOeySju+pJtq5hbQOWyR7bTuBIGiEs0UgsGfSM1P2GIkTBM=</Q>
<DP>oJxsI1su+qBHsUTlnwTHYgqQ8j0eawboNN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