Ejemplo n.º 1
0
        public string algoritmoHash(byte[] pArchivo, string algorithm)
        {
            Chilkat.Crypt2 crypt  = new Chilkat.Crypt2();
            bool           succes = crypt.UnlockComponent("Anything for 30-day trial");

            if (succes != true)
            {
                Console.WriteLine(crypt.LastErrorText);
                return("");
            }
            //  Set the name of the hash algorithm.
            //  Other choices include "sha1", "sha256", "sha384", "sha512", "md2", "md5", and "haval".
            crypt.HashAlgorithm = algorithm;

            //  EncodingMode specifies the encoding of the hash output.
            //  It may be "hex", "url", "base64", or "quoted-printable".
            crypt.EncodingMode = "hex";

            //  Files of any type may be hashed -- it doesn't matter
            //  if the file is binary or text...
            string hashStr;

            hashStr = crypt.HashBytesENC(pArchivo);
            if (crypt.LastMethodSuccess != true)
            {
                Console.WriteLine(crypt.LastErrorText);
                return("");
            }

            Console.WriteLine(hashStr);
            return(hashStr);
        }