コード例 #1
0
        public static StegoAlgorithm Create(AlgorithmEnum selection)
        {
            var type = Type.GetType(typeof(StegoAlgorithm).Namespace + "." + selection.ToString(), throwOnError: false);

            if (type == null)
            {
                throw new NullReferenceException(selection.ToString() + " is not a known algorithm type");
            }

            if (!typeof(StegoAlgorithm).IsAssignableFrom(type))
            {
                throw new InvalidOperationException(type.Name + " does not inherit from StegoAlghorithm");
            }

            return((StegoAlgorithm)Activator.CreateInstance(type));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: stephenreynolds/checkcheck
        static void CompareHash(string filePath, string hash, AlgorithmEnum algorithm)
        {
            string fileHash = ComputeHash(filePath, algorithm);

            // Make sure file hash was computed successfully and compare with given hash.
            if (fileHash == null)
            {
                Console.WriteLine("Invalid hashing algorithm given. Valid options are: MD5, SHA1, SHA256, SHA384, and SHA512.");
            }
            else if (fileHash == hash)
            {
                Console.WriteLine($"{Path.GetFileName(filePath)} validated succcessfully.");
            }
            else
            {
                Console.WriteLine($"{algorithm.ToString()} validation FAILED!");
                Console.WriteLine($"File hash is: \t\t\t{fileHash}\nBut the hash given was: \t{hash}");
            }
        }
コード例 #3
0
        public static string GetDescription(this AlgorithmEnum val)
        {
            var attributes = (DescriptionAttribute[])val.GetType().GetField(val.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);

            return(attributes.Length > 0 ? attributes[0].Description : string.Empty);
        }