Пример #1
7
       public static string encrypt(string toEncrypt)
        {
            if (toEncrypt == null) return null;
            byte[] data = System.Text.Encoding.UTF8.GetBytes(toEncrypt); 
            Sha256 sha = new Sha256();
            sha.AddData(data, 0, (uint)data.Length);

            ICollection<byte> hash = sha.GetHash();
            string hashPass = Sha256.ArrayToString(hash.ToList<byte>());
            return hashPass;
        }
Пример #2
1
        public static ReadOnlyCollection<byte> HashFile(Stream fs)
        {
            Sha256 sha = new Sha256();
            byte[] buf = new byte[8196];

            uint bytes_read;
            do
            {
                bytes_read = (uint)fs.Read(buf, 0, buf.Length);
                if (bytes_read == 0)
                    break;

                sha.AddData(buf, 0, bytes_read);
            }
            while (bytes_read == 8196);

            return sha.GetHash();
        }