Пример #1
0
        /// <summary>
        /// Computes a token for the specified file stream.
        /// </summary>
        /// <param name="stream">The file stream.</param>
        /// <returns>The token.</returns>
        public string ComputeToken(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            byte[] hashBytes;

            // Hash the incoming data
            using (var sha256Hash = new SHA256Managed())
            {
                stream.Position = 0;
                hashBytes       = sha256Hash.ComputeHash(stream);
            }

            stream.Position = 0;

            // Convert the hashed data to a Base32 string.
            return(Base32Encoding.ToBase32String(hashBytes));
        }
Пример #2
0
        public void ToBase32StringTests(byte[] input, string output)
        {
            var encodedString = Base32Encoding.ToBase32String(input);

            Assert.AreEqual(output, encodedString, "The encoded strings do not match");
        }
Пример #3
0
 public void ToBase32StringInvalidArgs()
 {
     Assert.That(() => Base32Encoding.ToBase32String(null),
                 Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("bytes"));
 }