Exemple #1
0
        public override void Create()
        {
            // try creating ourselve using Create
            HashAlgorithm h = MD2.Create("MD2Managed");

            Assert.IsTrue((h is MD2Managed), "MD2Managed");
        }
Exemple #2
0
        /// Encodes the specified string.
        /// @param text The string to encode.
        /// @returns The encoded string.
        public string Encode(string text)
        {
            var buffer = Encoding.Default.GetBytes(text);
            var hash   = MD2.Create().ComputeHash(buffer);

            return(HexCodec.GetString(hash));
        }
        public virtual void Create()
        {
            // create the default implementation
            HashAlgorithm h = MD2.Create();

            Assert.IsTrue((h is MD2Managed), "MD2Managed");
            // Note: will fail is default is changed in machine.config
        }
Exemple #4
0
        public static string Md2Crypto(string source)
        {
            using (MD2 myMD2 = MD2.Create())
            {
                try
                {
                    byte[] input  = Encoding.UTF8.GetBytes(source);
                    byte[] output = myMD2.ComputeHash(input);

                    string hashstr = GetHexStrByteArray(output);

                    return(hashstr);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }
        }
Exemple #5
0
        static internal HashAlgorithm CreateFromName(string name)
        {
#if FULL_AOT_RUNTIME
            switch (name)
            {
            case "MD2":
                return(MD2.Create());

            case "MD4":
                return(MD4.Create());

            case "MD5":
                return(MD5.Create());

            case "SHA1":
                return(SHA1.Create());

            case "SHA256":
                return(SHA256.Create());

            case "SHA384":
                return(SHA384.Create());

            case "SHA512":
                return(SHA512.Create());

            case "RIPEMD160":
                return(RIPEMD160.Create());

            default:
                try {
                    return((HashAlgorithm)Activator.CreateInstance(Type.GetType(name)));
                }
                catch {
                    throw new CryptographicException("Unsupported hash algorithm: " + name);
                }
            }
#else
            return(HashAlgorithm.Create(name));
#endif
        }