root/apps/outlook/trunk/DotTel/BouncyCastle/src/ocsp/OCSPUtil.cs
@
20
| Revision 20, 6.2 kB (checked in by root, 5 years ago) |
|---|
| Line | |
|---|---|
| 1 | using System; |
| 2 | using System.Collections; |
| 3 | using System.Globalization; |
| 4 | |
| 5 | using Org.BouncyCastle.Asn1; |
| 6 | using Org.BouncyCastle.Asn1.CryptoPro; |
| 7 | using Org.BouncyCastle.Asn1.Nist; |
| 8 | using Org.BouncyCastle.Asn1.Pkcs; |
| 9 | using Org.BouncyCastle.Asn1.TeleTrust; |
| 10 | using Org.BouncyCastle.Asn1.X509; |
| 11 | using Org.BouncyCastle.Asn1.X9; |
| 12 | using Org.BouncyCastle.Utilities.Collections; |
| 13 | |
| 14 | namespace Org.BouncyCastle.Ocsp |
| 15 | { |
| 16 | class OcspUtilities |
| 17 | { |
| 18 | private static readonly Hashtable algorithms = new Hashtable(); |
| 19 | private static readonly Hashtable oids = new Hashtable(); |
| 20 | private static readonly ISet noParams = new HashSet(); |
| 21 | |
| 22 | static OcspUtilities() |
| 23 | { |
| 24 | algorithms.Add("MD2WITHRSAENCRYPTION", PkcsObjectIdentifiers.MD2WithRsaEncryption); |
| 25 | algorithms.Add("MD2WITHRSA", PkcsObjectIdentifiers.MD2WithRsaEncryption); |
| 26 | algorithms.Add("MD5WITHRSAENCRYPTION", PkcsObjectIdentifiers.MD5WithRsaEncryption); |
| 27 | algorithms.Add("MD5WITHRSA", PkcsObjectIdentifiers.MD5WithRsaEncryption); |
| 28 | algorithms.Add("SHA1WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha1WithRsaEncryption); |
| 29 | algorithms.Add("SHA1WITHRSA", PkcsObjectIdentifiers.Sha1WithRsaEncryption); |
| 30 | algorithms.Add("SHA224WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha224WithRsaEncryption); |
| 31 | algorithms.Add("SHA224WITHRSA", PkcsObjectIdentifiers.Sha224WithRsaEncryption); |
| 32 | algorithms.Add("SHA256WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha256WithRsaEncryption); |
| 33 | algorithms.Add("SHA256WITHRSA", PkcsObjectIdentifiers.Sha256WithRsaEncryption); |
| 34 | algorithms.Add("SHA384WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha384WithRsaEncryption); |
| 35 | algorithms.Add("SHA384WITHRSA", PkcsObjectIdentifiers.Sha384WithRsaEncryption); |
| 36 | algorithms.Add("SHA512WITHRSAENCRYPTION", PkcsObjectIdentifiers.Sha512WithRsaEncryption); |
| 37 | algorithms.Add("SHA512WITHRSA", PkcsObjectIdentifiers.Sha512WithRsaEncryption); |
| 38 | algorithms.Add("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160); |
| 39 | algorithms.Add("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160); |
| 40 | algorithms.Add("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128); |
| 41 | algorithms.Add("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128); |
| 42 | algorithms.Add("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256); |
| 43 | algorithms.Add("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256); |
| 44 | algorithms.Add("SHA1WITHDSA", X9ObjectIdentifiers.IdDsaWithSha1); |
| 45 | algorithms.Add("DSAWITHSHA1", X9ObjectIdentifiers.IdDsaWithSha1); |
| 46 | algorithms.Add("SHA224WITHDSA", NistObjectIdentifiers.DsaWithSha224); |
| 47 | algorithms.Add("SHA256WITHDSA", NistObjectIdentifiers.DsaWithSha256); |
| 48 | algorithms.Add("SHA1WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha1); |
| 49 | algorithms.Add("ECDSAWITHSHA1", X9ObjectIdentifiers.ECDsaWithSha1); |
| 50 | algorithms.Add("SHA224WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha224); |
| 51 | algorithms.Add("SHA256WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha256); |
| 52 | algorithms.Add("SHA384WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha384); |
| 53 | algorithms.Add("SHA512WITHECDSA", X9ObjectIdentifiers.ECDsaWithSha512); |
| 54 | algorithms.Add("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94); |
| 55 | algorithms.Add("GOST3411WITHGOST3410-94", CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94); |
| 56 | |
| 57 | oids.Add(PkcsObjectIdentifiers.MD2WithRsaEncryption, "MD2WITHRSA"); |
| 58 | oids.Add(PkcsObjectIdentifiers.MD5WithRsaEncryption, "MD5WITHRSA"); |
| 59 | oids.Add(PkcsObjectIdentifiers.Sha1WithRsaEncryption, "SHA1WITHRSA"); |
| 60 | oids.Add(PkcsObjectIdentifiers.Sha224WithRsaEncryption, "SHA224WITHRSA"); |
| 61 | oids.Add(PkcsObjectIdentifiers.Sha256WithRsaEncryption, "SHA256WITHRSA"); |
| 62 | oids.Add(PkcsObjectIdentifiers.Sha384WithRsaEncryption, "SHA384WITHRSA"); |
| 63 | oids.Add(PkcsObjectIdentifiers.Sha512WithRsaEncryption, "SHA512WITHRSA"); |
| 64 | oids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD160, "RIPEMD160WITHRSA"); |
| 65 | oids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD128, "RIPEMD128WITHRSA"); |
| 66 | oids.Add(TeleTrusTObjectIdentifiers.RsaSignatureWithRipeMD256, "RIPEMD256WITHRSA"); |
| 67 | oids.Add(X9ObjectIdentifiers.IdDsaWithSha1, "SHA1WITHDSA"); |
| 68 | oids.Add(NistObjectIdentifiers.DsaWithSha224, "SHA224WITHDSA"); |
| 69 | oids.Add(NistObjectIdentifiers.DsaWithSha256, "SHA256WITHDSA"); |
| 70 | oids.Add(X9ObjectIdentifiers.ECDsaWithSha1, "SHA1WITHECDSA"); |
| 71 | oids.Add(X9ObjectIdentifiers.ECDsaWithSha224, "SHA224WITHECDSA"); |
| 72 | oids.Add(X9ObjectIdentifiers.ECDsaWithSha256, "SHA256WITHECDSA"); |
| 73 | oids.Add(X9ObjectIdentifiers.ECDsaWithSha384, "SHA384WITHECDSA"); |
| 74 | oids.Add(X9ObjectIdentifiers.ECDsaWithSha512, "SHA512WITHECDSA"); |
| 75 | oids.Add(CryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94, "GOST3411WITHGOST3410"); |
| 76 | |
| 77 | // |
| 78 | // According to RFC 3279, the ASN.1 encoding SHALL (id-dsa-with-sha1) or MUST (ecdsa-with-SHA*) omit the parameters field. |
| 79 | // The parameters field SHALL be NULL for RSA based signature algorithms. |
| 80 | // |
| 81 | noParams.Add(X9ObjectIdentifiers.ECDsaWithSha1); |
| 82 | noParams.Add(X9ObjectIdentifiers.ECDsaWithSha224); |
| 83 | noParams.Add(X9ObjectIdentifiers.ECDsaWithSha256); |
| 84 | noParams.Add(X9ObjectIdentifiers.ECDsaWithSha384); |
| 85 | noParams.Add(X9ObjectIdentifiers.ECDsaWithSha512); |
| 86 | noParams.Add(X9ObjectIdentifiers.IdDsaWithSha1); |
| 87 | noParams.Add(NistObjectIdentifiers.DsaWithSha224); |
| 88 | noParams.Add(NistObjectIdentifiers.DsaWithSha256); |
| 89 | } |
| 90 | |
| 91 | internal static DerObjectIdentifier GetAlgorithmOid( |
| 92 | string algorithmName) |
| 93 | { |
| 94 | algorithmName = algorithmName.ToUpper(CultureInfo.InvariantCulture); |
| 95 | |
| 96 | if (algorithms.ContainsKey(algorithmName)) |
| 97 | { |
| 98 | return (DerObjectIdentifier)algorithms[algorithmName]; |
| 99 | } |
| 100 | |
| 101 | return new DerObjectIdentifier(algorithmName); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | internal static string GetAlgorithmName( |
| 106 | DerObjectIdentifier oid) |
| 107 | { |
| 108 | if (oids.ContainsKey(oid)) |
| 109 | { |
| 110 | return (string)oids[oid]; |
| 111 | } |
| 112 | |
| 113 | return oid.Id; |
| 114 | } |
| 115 | |
| 116 | internal static AlgorithmIdentifier GetSigAlgID( |
| 117 | DerObjectIdentifier sigOid) |
| 118 | { |
| 119 | if (noParams.Contains(sigOid)) |
| 120 | { |
| 121 | return new AlgorithmIdentifier(sigOid); |
| 122 | } |
| 123 | |
| 124 | return new AlgorithmIdentifier(sigOid, DerNull.Instance); |
| 125 | } |
| 126 | |
| 127 | internal static IEnumerable AlgNames |
| 128 | { |
| 129 | get { return new EnumerableProxy(algorithms.Keys); } |
| 130 | } |
| 131 | } |
| 132 | } |
Note: See TracBrowser
for help on using the browser.








