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 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
|
//
// CryptoConfig.cs: Handles cryptographic implementations and OIDs mappings.
//
// Authors:
// Sebastien Pouliot (sebastien@xamarin.com)
// Tim Coleman (tim@timcoleman.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
// Copyright (C) Tim Coleman, 2004
// Copyright (C) 2004-2007,2011 Novell, Inc (http://www.novell.com)
// Copyright 2011 Xamarin, Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if FULL_AOT_RUNTIME
// This is a special version of CryptoConfig that is not configurable and
// every "choice" is statiscally compiled. As long as CreateFromName is not
// used the linker will be able to eliminate the crypto code from the applications
using System.Runtime.InteropServices;
using System.Security.Permissions;
namespace System.Security.Cryptography {
[ComVisible (true)]
public partial class CryptoConfig {
// try to avoid hitting the CreateFromName overloads to help the linker
public static object CreateFromName (string name)
{
return CreateFromName (name, null);
}
[PermissionSet (SecurityAction.LinkDemand, Unrestricted = true)]
public static object CreateFromName (string name, params object[] args)
{
if (name == null)
throw new ArgumentNullException ("name");
switch (name.ToLowerInvariant ()) {
case "system.security.cryptography.dsacryptoserviceprovider":
case "system.security.cryptography.dsa":
case "dsa":
return new DSACryptoServiceProvider ();
case "system.security.cryptography.dsasignaturedeformatter":
return new DSASignatureDeformatter ();
case "system.security.cryptography.dsasignatureformatter":
return new DSASignatureFormatter ();
case "system.security.cryptography.dsasignaturedescription":
case "http://www.w3.org/2000/09/xmldsig#dsa-sha1":
return new DSASignatureDescription ();
case "system.security.cryptography.descryptoserviceprovider":
case "system.security.cryptography.des":
case "des":
return new DESCryptoServiceProvider ();
case "system.security.cryptography.hmacmd5":
case "hmacmd5":
return new HMACMD5 ();
case "system.security.cryptography.hmacripemd160":
case "hmacripemd160":
case "http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160":
return new HMACRIPEMD160 ();
case "system.security.cryptography.keyedhashalgorithm":
case "system.security.cryptography.hmac":
case "system.security.cryptography.hmacsha1":
case "hmacsha1":
return new HMACSHA1 ();
case "system.security.cryptography.hmacsha256":
case "hmacsha256":
case "http://www.w3.org/2001/04/xmldsig-more#hmac-sha256":
return new HMACSHA256 ();
case "system.security.cryptography.hmacsha384":
case "hmacsha384":
case "http://www.w3.org/2001/04/xmldsig-more#hmac-sha384":
return new HMACSHA384 ();
case "system.security.cryptography.hmacsha512":
case "hmacsha512":
case "http://www.w3.org/2001/04/xmldsig-more#hmac-sha512":
return new HMACSHA512 ();
case "system.security.cryptography.mactripledes":
case "mactripledes":
return new MACTripleDES ();
case "system.security.cryptography.md5cryptoserviceprovider":
case "system.security.cryptography.md5":
case "md5":
return new MD5CryptoServiceProvider ();
case "system.security.cryptography.rc2cryptoserviceprovider":
case "system.security.cryptography.rc2":
case "rc2":
return new RC2CryptoServiceProvider ();
case "system.security.cryptography.symmetricalgorithm":
case "system.security.cryptography.rijndaelmanaged":
case "system.security.cryptography.rijndael":
case "rijndael":
return new RijndaelManaged ();
case "system.security.cryptography.ripemd160managed":
case "system.security.cryptography.ripemd160":
case "ripemd-160":
case "ripemd160":
return new RIPEMD160Managed ();
case "system.security.cryptography.rngcryptoserviceprovider":
case "system.security.cryptography.randomnumbergenerator":
case "randomnumbergenerator":
return new RNGCryptoServiceProvider ();
case "system.security.cryptography.asymmetricalgorithm":
case "system.security.cryptography.rsa":
case "rsa":
return new RSACryptoServiceProvider ();
case "system.security.cryptography.rsapkcs1signaturedeformatter":
return new RSAPKCS1SignatureDeformatter ();
case "system.security.cryptography.rsapkcs1signatureformatter":
return new RSAPKCS1SignatureFormatter ();
case "system.security.cryptography.rsapkcs1sha1signaturedescription":
case "http://www.w3.org/2000/09/xmldsig#rsa-sha1":
return new RSAPKCS1SHA1SignatureDescription ();
case "system.security.cryptography.hashalgorithm":
case "system.security.cryptography.sha1":
case "system.security.cryptography.sha1cryptoserviceprovider":
case "sha1":
case "sha":
case "http://www.w3.org/2000/09/xmldsig#sha1":
return new SHA1CryptoServiceProvider ();
case "system.security.cryptography.sha1managed":
return new SHA1Managed ();
case "system.security.cryptography.sha256managed":
case "system.security.cryptography.sha256":
case "sha256":
case "sha-256":
case "http://www.w3.org/2001/04/xmlenc#sha256":
return new SHA256Managed ();
case "system.security.cryptography.sha384managed":
case "system.security.cryptography.sha384":
case "sha384":
case "sha-384":
return new SHA384Managed ();
case "system.security.cryptography.sha512managed":
case "system.security.cryptography.sha512":
case "sha512":
case "sha-512":
case "http://www.w3.org/2001/04/xmlenc#sha512":
return new SHA512Managed ();
case "system.security.cryptography.tripledescryptoserviceprovider":
case "system.security.cryptography.tripledes":
case "triple des":
case "tripledes":
case "3des":
return new TripleDESCryptoServiceProvider ();
case "x509chain":
name = "System.Security.Cryptography.X509Certificates.X509Chain, System";
break;
case "aes":
#if MOBILE_STATIC
name = "System.Security.Cryptography.AesCryptoServiceProvider, System.Core";
#else
name = "System.Security.Cryptography.AesManaged, System.Core";
#endif
break;
}
try {
// last resort, the request type might be available (if care is taken for the type not to be linked
// away) and that can allow some 3rd party code to work (e.g. extra algorithms) and make a few more
// unit tests happy
return Activator.CreateInstance (Type.GetType (name));
}
catch {
// method doesn't throw any exception
return null;
}
}
internal static string MapNameToOID (string name, object arg)
{
return MapNameToOID (name);
}
public static string MapNameToOID (string name)
{
if (name == null)
throw new ArgumentNullException ("name");
switch (name.ToLowerInvariant ()) {
case "system.security.cryptography.sha1cryptoserviceprovider":
case "system.security.cryptography.sha1managed":
case "system.security.cryptography.sha1":
case "sha1":
return "1.3.14.3.2.26";
case "system.security.cryptography.md5cryptoserviceprovider":
case "system.security.cryptography.md5":
case "md5":
return "1.2.840.113549.2.5";
case "system.security.cryptography.sha256managed":
case "system.security.cryptography.sha256":
case "sha256":
return "2.16.840.1.101.3.4.2.1";
case "system.security.cryptography.sha384managed":
case "system.security.cryptography.sha384":
case "sha384":
return "2.16.840.1.101.3.4.2.2";
case "system.security.cryptography.sha512managed":
case "system.security.cryptography.sha512":
case "sha512":
return "2.16.840.1.101.3.4.2.3";
case "system.security.cryptography.ripemd160managed":
case "system.security.cryptography.ripemd160":
case "ripemd160":
return "1.3.36.3.2.1";
case "tripledeskeywrap":
return "1.2.840.113549.1.9.16.3.6";
case "des":
return "1.3.14.3.2.7";
case "tripledes":
return "1.2.840.113549.3.7";
case "rc2":
return "1.2.840.113549.3.2";
default:
return null;
}
}
}
}
#endif
|