コード例 #1
0
        public void HashAlgorithmWrapper_Dispose_NonOwner_DoesNotThrow()
        {
            var haw = new HashAlgorithmWrapper(new SHA1Managed(), false);


            haw.Dispose();
        }
コード例 #2
0
        public void HashAlgorithmWrapper_Generic_Dispose_DoesNotThrow()
        {
            var haw = new HashAlgorithmWrapper <SHA1Managed>();

            Assert.DoesNotThrow(() =>
                                haw.Dispose());
        }
コード例 #3
0
        public void HashAlgorithmWrapper_Dispose_Owner_Invalidates()
        {
            var ha  = new SHA1Managed();
            var haw = new HashAlgorithmWrapper(ha, true);


            Assert.DoesNotThrow(() =>
                                haw.Dispose());


            // HashAlgorithm shouldn't be usable anymore.
            Assert.Throws <ObjectDisposedException>(() =>
                                                    ha.ComputeHash(new byte[0]));

            Assert.Throws <ObjectDisposedException>(() =>
                                                    ha.ComputeHash(new MemoryStream()));


            // HashAlgorithmWrapper should not be usable anymore either.
            Assert.Throws <ObjectDisposedException>(() =>
                                                    haw.ComputeHash(new byte[0]));

            Assert.Throws <ObjectDisposedException>(() =>
                                                    haw.ComputeHash(new MemoryStream()));
        }
コード例 #4
0
        public void HashAlgorithmWrapper_Dispose_Owner_DoesNotThrow()
        {
            var haw = new HashAlgorithmWrapper(new SHA1Managed(), true);


            Assert.DoesNotThrow(() =>
                                haw.Dispose());
        }
コード例 #5
0
        /// <summary>
        /// Подписать данные.
        /// </summary>
        /// <param name="data">Данные (массив байт).</param>
        /// <param name="hashAlgorithmWrapper">Обертка над алгоритмом хеширования.</param>
        /// <returns>Подпись.</returns>
        /// <remarks>Необходимо вернуть "сырую подпись" (не CMS).</remarks>
        public byte[] SignData(byte[] data, HashAlgorithmWrapper hashAlgorithmWrapper)
        {
            /* Например:
             *  var cryptoServiceProvider = (RSACryptoServiceProvider)this.Certificate.PrivateKey;
             *  using (var hashAlgorithm = hashAlgorithmWrapper.GetHashAlgorithm())
             *    return cryptoServiceProvider.SignHash(hashAlgorithm.ComputeHash(data), hashAlgorithmWrapper.AlgorithmId);
             */

            throw new NotImplementedException();
        }
コード例 #6
0
        /// <summary>
        /// Проверить подпись данных.
        /// </summary>
        /// <param name="data">Данные (массив байт).</param>
        /// <param name="signature">Подписанные данные.</param>
        /// <param name="hashAlgorithmWrapper">Обертка над алгоритмом хеширования.</param>
        /// <returns></returns>
        /// <remarks>Проверяется "сырая подпись" (не CMS).</remarks>
        public bool VerifySignature(byte[] data, byte[] signature, HashAlgorithmWrapper hashAlgorithmWrapper)
        {
            /* Например:
             *  var cryptoServiceProvider = (RSACryptoServiceProvider)this.Certificate.PublicKey.Key;
             *  var hash = hashAlgorithmWrapper.ComputeHash(data);
             *  return cryptoServiceProvider.VerifyHash(hash, hashAlgorithmWrapper.AlgorithmId, signature);
             */

            throw new NotImplementedException();
        }
コード例 #7
0
        public void HashAlgorithmWrapper_Generic_Dispose_Invalidates()
        {
            var haw = new HashAlgorithmWrapper <SHA1Managed>();

            haw.Dispose();


            // HashAlgorithmWrapper should no longer be usable.
            Assert.Throws <ObjectDisposedException>(() =>
                                                    haw.ComputeHash(new byte[0]));

            Assert.Throws <ObjectDisposedException>(() =>
                                                    haw.ComputeHash(new MemoryStream()));
        }
コード例 #8
0
        public void HashAlgorithmWrapper_Dispose_NonOwner_Preserves_HashAlgorithm()
        {
            var ha  = new SHA1Managed();
            var haw = new HashAlgorithmWrapper(ha, false);


            haw.Dispose();


            // HashAlgorithm should still be usable.
            ha.ComputeHash(new byte[0]);
            ha.ComputeHash(new MemoryStream());


            // HashAlgorithmWrapper's usability afterwards is an implementation detail
            //   and shouldn't be tested.
        }