Example #1
0
 private static AlgorithmIdentifier GetAlgorithmIdentifier(string mechanism, DefaultSignatureAlgorithmIdentifierFinder finder)
 {
     try
     {
         return(finder.Find(mechanism));
     }
     catch
     {
         return(null);
     }
 }
Example #2
0
        private static void Test2()
        {
            List <string> hashs = new List <string>();
            Type          type  = typeof(HashAlgorithmHelper);

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Static | BindingFlags.Public);
            foreach (PropertyInfo property in properties)
            {
                if (property.GetValue(type, null) is IHashAlgorithm algorithm)
                {
                    hashs.Add(algorithm.Mechanism);
                }
            }
            List <string> algorithms = new List <string>();

            string[] suffixs = new string[] { "CVC-ECDSA", "PLAIN-ECDSA", "DSA", "RSA", "ECDSA", "ECGOST3410", "ECNR", "GOST3410", "RSA/X9.31", "ISO9796-2", "RSAANDMGF1", "SM2" };
            foreach (string suffix in suffixs)
            {
                foreach (string prefix in hashs)
                {
                    algorithms.Add(prefix + "with" + suffix);
                }
            }
            SecureRandom random = SecureRandom.GetInstance("MD5PRNG");
            var          rsa    = new LH.BouncyCastle.Helpers.Security.Crypto.Asymmetric.RSA(768, 8);
            var          key    = rsa.GenerateKeyPair().Private;
            DefaultSignatureAlgorithmIdentifierFinder finder = new DefaultSignatureAlgorithmIdentifierFinder();

            foreach (string algorithm in algorithms)
            {
                _total++;
                _execute++;
                string tag1 = "------------------------------- ";
                string tag2 = "x";
                string tag3 = "x";
                bool   oidy = false;
                try
                {
                    var identifier = finder.Find(algorithm);
                    tag1 = identifier.Algorithm.Id;
                    oidy = true;
                }
                catch { }
                try
                {
                    _    = new Asn1SignatureFactory(algorithm, key, random);
                    tag2 = "X509 name availabled.";
                }
                catch { }
                if (oidy)
                {
                    try
                    {
                        _    = new Asn1SignatureFactory(tag1, key, random);
                        tag3 = "X509 oid availabled.";
                    }
                    catch { }
                }
                Console.WriteLine("{0}{1}{2}{3}", algorithm.PadRight(38), tag1.PadRight(32), tag2.PadRight(24), tag3);
            }
        }