2 // Oid.cs - System.Security.Cryptography.Oid
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2005 Novell Inc. (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using System.Security.Cryptography.X509Certificates;
34 namespace System.Security.Cryptography {
36 public sealed class Oid {
38 private string _value;
47 public Oid (string oid)
50 throw new ArgumentNullException ("oid");
53 _name = GetName (oid);
56 public Oid (string value, string friendlyName)
65 throw new ArgumentNullException ("oid");
68 _name = oid.FriendlyName;
73 public string FriendlyName {
77 _value = GetValue (_name);
82 get { return _value; }
85 _name = GetName (_value);
91 // Known OID/Names not defined anywhere else (by OID order)
92 internal const string oidRSA = "1.2.840.113549.1.1.1";
93 internal const string nameRSA = "RSA";
94 internal const string oidPkcs7Data = "1.2.840.113549.1.7.1";
95 internal const string namePkcs7Data = "PKCS 7 Data";
96 internal const string oidPkcs9ContentType = "1.2.840.113549.1.9.3";
97 internal const string namePkcs9ContentType = "Content Type";
98 internal const string oidPkcs9MessageDigest = "1.2.840.113549.1.9.4";
99 internal const string namePkcs9MessageDigest = "Message Digest";
100 internal const string oidPkcs9SigningTime = "1.2.840.113549.1.9.5";
101 internal const string namePkcs9SigningTime = "Signing Time";
102 internal const string oidMd5 = "1.2.840.113549.2.5";
103 internal const string nameMd5 = "md5";
104 internal const string oid3Des = "1.2.840.113549.3.7";
105 internal const string name3Des = "3des";
106 internal const string oidSha1 = "1.3.14.3.2.26";
107 internal const string nameSha1 = "sha1";
108 internal const string oidSubjectAltName = "2.5.29.17";
109 internal const string nameSubjectAltName = "Subject Alternative Name";
110 internal const string oidAes128 = "2.16.840.1.101.3.4.1.2";
111 internal const string nameAes128 = "aes128";
112 internal const string oidAes256 = "2.16.840.1.101.3.4.1.42";
113 internal const string nameAes256 = "aes256";
114 internal const string oidSha256 = "2.16.840.1.101.3.4.2.1";
115 internal const string nameSha256 = "sha256";
116 internal const string oidSha512 = "2.16.840.1.101.3.4.2.3";
117 internal const string nameSha512 = "sha512";
118 internal const string oidNetscapeCertType = "2.16.840.1.113730.1.1";
119 internal const string nameNetscapeCertType = "Netscape Cert Type";
121 // TODO - find the complete list
122 private string GetName (string oid)
128 return namePkcs7Data;
129 case oidPkcs9ContentType:
130 return namePkcs9ContentType;
131 case oidPkcs9MessageDigest:
132 return namePkcs9MessageDigest;
133 case oidPkcs9SigningTime:
134 return namePkcs9SigningTime;
137 case X509BasicConstraintsExtension.oid:
138 return X509BasicConstraintsExtension.friendlyName;
139 case X509KeyUsageExtension.oid:
140 return X509KeyUsageExtension.friendlyName;
141 case X509EnhancedKeyUsageExtension.oid:
142 return X509EnhancedKeyUsageExtension.friendlyName;
143 case X509SubjectKeyIdentifierExtension.oid:
144 return X509SubjectKeyIdentifierExtension.friendlyName;
145 case oidSubjectAltName:
146 return nameSubjectAltName;
147 case oidNetscapeCertType:
148 return nameNetscapeCertType;
166 // TODO - find the complete list
167 private string GetValue (string name)
174 case namePkcs9ContentType:
175 return oidPkcs9ContentType;
176 case namePkcs9MessageDigest:
177 return oidPkcs9MessageDigest;
178 case namePkcs9SigningTime:
179 return oidPkcs9SigningTime;
182 case X509BasicConstraintsExtension.friendlyName:
183 return X509BasicConstraintsExtension.oid;
184 case X509KeyUsageExtension.friendlyName:
185 return X509KeyUsageExtension.oid;
186 case X509EnhancedKeyUsageExtension.friendlyName:
187 return X509EnhancedKeyUsageExtension.oid;
188 case X509SubjectKeyIdentifierExtension.friendlyName:
189 return X509SubjectKeyIdentifierExtension.oid;
190 case nameSubjectAltName:
191 return oidSubjectAltName;
192 case nameNetscapeCertType:
193 return oidNetscapeCertType;