2 // System.Security.Cryptography.CngKeyBlobFormat
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
8 // Copyright (C) 2011 Juho Vähä-Herttua
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 namespace System.Security.Cryptography {
34 // note: CNG stands for "Cryptography API: Next Generation"
37 public sealed class CngKeyBlobFormat : IEquatable<CngKeyBlobFormat> {
39 private string m_format;
41 public CngKeyBlobFormat (string format)
44 throw new ArgumentNullException ("format");
45 if (format.Length == 0)
46 throw new ArgumentException ("format");
51 public string Format {
52 get { return m_format; }
55 public bool Equals (CngKeyBlobFormat other)
59 return m_format == other.m_format;
62 public override bool Equals (object obj)
64 return Equals (obj as CngKeyBlobFormat);
67 public override int GetHashCode ()
69 return m_format.GetHashCode ();
72 public override string ToString ()
79 private static CngKeyBlobFormat opaqueTransportBlob;
80 private static CngKeyBlobFormat genericPrivateBlob;
81 private static CngKeyBlobFormat genericPublicBlob;
82 private static CngKeyBlobFormat eccPrivateBlob;
83 private static CngKeyBlobFormat eccPublicBlob;
84 private static CngKeyBlobFormat pkcs8PrivateBlob;
86 public static CngKeyBlobFormat OpaqueTransportBlob {
88 if (opaqueTransportBlob == null)
89 opaqueTransportBlob = new CngKeyBlobFormat ("OpaqueTransport");
90 return opaqueTransportBlob;
94 public static CngKeyBlobFormat GenericPrivateBlob {
96 if (genericPrivateBlob == null)
97 genericPrivateBlob = new CngKeyBlobFormat ("PRIVATEBLOB");
98 return genericPrivateBlob;
102 public static CngKeyBlobFormat GenericPublicBlob {
104 if (genericPublicBlob == null)
105 genericPublicBlob = new CngKeyBlobFormat ("PUBLICBLOB");
106 return genericPublicBlob;
110 public static CngKeyBlobFormat EccPrivateBlob {
112 if (eccPrivateBlob == null)
113 eccPrivateBlob = new CngKeyBlobFormat ("ECCPRIVATEBLOB");
114 return eccPrivateBlob;
118 public static CngKeyBlobFormat EccPublicBlob {
120 if (eccPublicBlob == null)
121 eccPublicBlob = new CngKeyBlobFormat ("ECCPUBLICBLOB");
122 return eccPublicBlob;
126 public static CngKeyBlobFormat Pkcs8PrivateBlob {
128 if (pkcs8PrivateBlob == null)
129 pkcs8PrivateBlob = new CngKeyBlobFormat ("PKCS8_PRIVATEKEY");
130 return pkcs8PrivateBlob;
134 public static bool operator == (CngKeyBlobFormat left, CngKeyBlobFormat right)
136 if ((object)left == null)
137 return ((object)right == null);
138 return left.Equals (right);
141 public static bool operator != (CngKeyBlobFormat left, CngKeyBlobFormat right)
143 if ((object)left == null)
144 return ((object)right != null);
145 return !left.Equals (right);