Exemplo n.º 1
0
        public void Sha384Hash_GetHash_Null_3()
        {
            IHash hashAlgo = new Sha384Hash();

            Action action = () => hashAlgo.GetHash(null as FileInfo);

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 2
0
        public void Sha384Hash_GetHash_Empty()
        {
            IHash hashAlgo = new Sha384Hash();

            Action action = () => hashAlgo.GetHash(string.Empty);

            action.Should().Throw <ArgumentNullException>();
        }
Exemplo n.º 3
0
        public void Sha384Hash_GetHash_Valid_2()
        {
            IHash hashAlgo = new Sha384Hash();

            HashResult hashResult = hashAlgo.GetHash(Data.ExpectedHashFilePath);

            hashResult.Algorithm.Should().Be(Hashing.ExpectedSha384Algorithm);
            hashResult.Value.Should().Be(Hashing.ExpectedSha384Hash);
        }
Exemplo n.º 4
0
        public void Sha384Hash_GetHash_Valid_1()
        {
            IHash hashAlgo = new Sha384Hash();

            using FileStream fileStream = new(Data.ExpectedHashFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);

            HashResult hashResult = hashAlgo.GetHash(fileStream);

            hashResult.Algorithm.Should().Be(Hashing.ExpectedSha384Algorithm);
            hashResult.Value.Should().Be(Hashing.ExpectedSha384Hash);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 散列服务创造器
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public IHash CreateHash(Type type)
        {
            IHash hash;

            switch (type)
            {
            case Type.Md5:
                hash = new MD5Hash();
                break;

            case Type.Sha1:
                hash = new Sha1Hash();
                break;

            case Type.Sha256:
                hash = new Sha256Hash();
                break;

            case Type.Sha384:
                hash = new Sha384Hash();
                break;

            case Type.Sha512:
                hash = new Sha512Hash();
                break;

            case Type.RipEmd160:
                hash = new RipEmd160Hash();
                break;

            default:
                hash = new MD5Hash();
                break;
            }
            return(hash);
        }