当前位置: 首页>>代码示例>>C#>>正文


C# HashAlgorithm.TransformBlock方法代码示例

本文整理汇总了C#中System.Security.Cryptography.HashAlgorithm.TransformBlock方法的典型用法代码示例。如果您正苦于以下问题:C# HashAlgorithm.TransformBlock方法的具体用法?C# HashAlgorithm.TransformBlock怎么用?C# HashAlgorithm.TransformBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.HashAlgorithm的用法示例。


在下文中一共展示了HashAlgorithm.TransformBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ComputeHash

 public void ComputeHash(HashAlgorithm hash)
 {
     byte[] tmp = Encoding.UTF8.GetBytes (_name);
     hash.TransformBlock (tmp, 0, tmp.Length, null, 0);
     tmp = Encoding.UTF8.GetBytes (_body);
     hash.TransformBlock (tmp, 0, tmp.Length, null, 0);
 }
开发者ID:kazuki,项目名称:p2pncs,代码行数:7,代码来源:SimpleBBSRecord.cs

示例2: WriteHash

 public void WriteHash(HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc)
 {
     UTF8Encoding encoding = new UTF8Encoding(false);
     byte[] bytes = encoding.GetBytes(" " + this.Name + "=\"");
     hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
     bytes = encoding.GetBytes(System.Security.Cryptography.Xml.Utils.EscapeAttributeValue(this.Value));
     hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
     bytes = encoding.GetBytes("\"");
     hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:10,代码来源:CanonicalXmlAttribute.cs

示例3: StartTests

 protected int StartTests(HashAlgorithm hash, byte[] input, byte[] result)
 {
     try {
         byte[] ch = hash.ComputeHash(input, 0, input.Length);
         if (!ArrayEquals(ch, result))
             AddError("HB-ST1");
     } catch {
         AddError("HB-ST2");
     }
     try {
         // feed input byte-by-byte
         for(int i = 0; i < input.Length - 1; i++) {
             hash.TransformBlock(input, i, 1, input, i);
         }
         if (input.Length > 0)
             hash.TransformFinalBlock(input, input.Length - 1, 1);
         else
             hash.TransformFinalBlock(input, 0, 0);
         if (!ArrayEquals(hash.Hash, result)) {
             AddError("HB-ST3");
             Console.WriteLine(Encoding.ASCII.GetString(input));
         }
     } catch {
         AddError("HB-ST4");
     } finally {
         hash.Initialize();
     }
     return 4;
 }
开发者ID:maikgreubel,项目名称:securitylibrary,代码行数:29,代码来源:HashBox.cs

示例4: WriteHash

 public void WriteHash(HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc)
 {
     if (this.IsInNodeSet)
     {
         byte[] bytes = new UTF8Encoding(false).GetBytes(System.Security.Cryptography.Xml.Utils.EscapeTextData(this.Value));
         hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:CanonicalXmlText.cs

示例5: WriteHash

 public void WriteHash(HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc)
 {
     if (IsInNodeSet)
     {
         UTF8Encoding utf8 = new UTF8Encoding(false);
         byte[] rgbData = utf8.GetBytes(Utils.EscapeTextData(Value));
         hash.TransformBlock(rgbData, 0, rgbData.Length, rgbData, 0);
     }
 }
开发者ID:PKRoma,项目名称:corefx,代码行数:9,代码来源:CanonicalXmlText.cs

示例6: AddFileToHash

 private static void AddFileToHash(string filename, HashAlgorithm hashService, StreamFilter filter = null, Encoding encoding = null)
 {
     if (filter == null || filter == StreamFilter.None)
     {
         using (var stream = File.OpenRead(filename))
         {
             var buffer = new byte[1200000];
             var bytesRead = stream.Read(buffer, 0, buffer.Length);
             while (bytesRead > 1)
             {
                 hashService.TransformBlock(buffer, 0, bytesRead, buffer, 0);
                 bytesRead = stream.Read(buffer, 0, buffer.Length);
             }
         }
     }
     else
     {
         if (encoding == null)
         {
             if (Path.GetExtension(filename).Equals(".res", StringComparison.InvariantCultureIgnoreCase))
             {
                 encoding = Encoding.Unicode;
             }
             else
             {
                 encoding = Encoding.Default;
             }
         }
         using (var stream = File.OpenRead(filename))
         {
             using (var reader = new StreamReader(stream, encoding))
             {
                 foreach (var line in filter.ReadAllLines(reader))
                 {
                     var lineBuffer = encoding.GetBytes(line);
                     hashService.TransformBlock(lineBuffer, 0, lineBuffer.Length, lineBuffer, 0);
                 }
             }
         }
     }
 }
开发者ID:benjamine,项目名称:AssemblyHasher,代码行数:41,代码来源:FileHasher.cs

示例7: FIPS186_e

 public void FIPS186_e(string testName, HashAlgorithm hash, byte[] input, byte[] result)
 {
     byte[] copy = new byte [input.Length];
     for (int i=0; i < input.Length - 1; i++)
         hash.TransformBlock (input, i, 1, copy, i);
     hash.TransformFinalBlock (input, input.Length - 1, 1);
     // LAMESPEC or FIXME: TransformFinalBlock doesn't return HashValue !
     // AssertEquals (testName + ".e.1", result, output);
     Assert.AreEqual (result, hash.Hash, testName + ".e");
     // required or next operation will still return old hash
     hash.Initialize ();
 }
开发者ID:amatai,项目名称:crimson,代码行数:12,代码来源:SHA1Test.cs

示例8: WriteHash

 public void WriteHash(HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc)
 {
     if (this.IsInNodeSet)
     {
         byte[] bytes;
         UTF8Encoding encoding = new UTF8Encoding(false);
         if (docPos == DocPosition.AfterRootElement)
         {
             bytes = encoding.GetBytes("(char) 10");
             hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         }
         bytes = encoding.GetBytes("<?");
         hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         bytes = encoding.GetBytes(this.Name);
         hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         if ((this.Value != null) && (this.Value.Length > 0))
         {
             bytes = encoding.GetBytes(" " + this.Value);
             hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         }
         bytes = encoding.GetBytes("?>");
         hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         if (docPos == DocPosition.BeforeRootElement)
         {
             bytes = encoding.GetBytes("(char) 10");
             hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:29,代码来源:CanonicalXmlProcessingInstruction.cs

示例9: PrepareResume

        /// <summary>
        /// Prepares to resume.
        /// </summary>
        /// <param name="successfulLength">Successful length.</param>
        /// <param name="successfulPart">Successful part.</param>
        /// <param name="hashAlg">Hash algorithm</param>
        public static void PrepareResume(long successfulLength, Stream successfulPart, HashAlgorithm hashAlg) {
            byte[] buffer = new byte[4096];
            int pos = 0;
            while (pos < successfulLength) {
                int l = successfulPart.Read(buffer, 0, (int)Math.Min(buffer.Length, successfulLength - pos));
                if (l <= 0) {
                    throw new IOException(string.Format("File stream is shorter ({0}) than the given length {1}", pos, successfulLength));
                }

                hashAlg.TransformBlock(buffer, 0, l, buffer, 0);
                pos += l;
            }
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:19,代码来源:ContentTaskUtils.cs

示例10: HashTransformer

        public HashTransformer(StateHash hash)
        {
            mHash = hash;
            if (hash == null)
                return;

            mHasher = new SHA256Cng();

            var bytes = mHash.GetBytes();
            mHasher.TransformBlock(bytes, 0, bytes.Length, null, 0);

            mCryptoStream = new CryptoStream(new FakeStream(), mHasher, CryptoStreamMode.Write);
        }
开发者ID:aiedail92,项目名称:DBBranchManager,代码行数:13,代码来源:HashTransformer.cs

示例11: WriteHash

 public void WriteHash(HashAlgorithm hash, DocPosition docPos, AncestralNamespaceContextManager anc)
 {
     if (this.IsInNodeSet && this.IncludeComments)
     {
         UTF8Encoding encoding = new UTF8Encoding(false);
         byte[] bytes = encoding.GetBytes("(char) 10");
         if (docPos == DocPosition.AfterRootElement)
         {
             hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         }
         bytes = encoding.GetBytes("<!--");
         hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         bytes = encoding.GetBytes(this.Value);
         hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         bytes = encoding.GetBytes("-->");
         hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         if (docPos == DocPosition.BeforeRootElement)
         {
             bytes = encoding.GetBytes("(char) 10");
             hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
         }
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:CanonicalXmlComment.cs

示例12: ComputeHash

 public byte[] ComputeHash(FileStream fileStream, HashAlgorithm hashAlgorithm, byte[] buffer)
 {
     while (true)
     {
         int bytesRead = fileStream.Read(buffer, 0, buffer.Length);
         if (bytesRead == buffer.Length)
         {
             hashAlgorithm.TransformBlock(buffer, 0, bytesRead, buffer, 0);
         }
         else
         {
             hashAlgorithm.TransformFinalBlock(buffer, 0, bytesRead);
             return hashAlgorithm.Hash;
         }
     }
 }
开发者ID:simony,项目名称:WinUtils,代码行数:16,代码来源:LocalHash.cs

示例13: ComputeHash

        /// <summary>
        /// Computes a file hash without loading the entire file into memory.
        /// </summary>
        /// <param name="filePath">Path of the file to hash.</param>
        /// <param name="hashAlgorithm">Algorithm to hash in.  Example: 'new SHA1CryptoServiceProvider()'</param>
        /// <returns></returns>
        public static string ComputeHash(string filePath, HashAlgorithm hashAlgorithm)
        {
            try
            {
                using (var stream = (Stream)File.Open(filePath, FileMode.Open))
                {
                    int _bufferSize = 4096; // this makes it impossible to change the buffer size while computing

                    byte[] readAheadBuffer, buffer;
                    int readAheadBytesRead, bytesRead;
                    long size, totalBytesRead = 0;

                    size = stream.Length;
                    readAheadBuffer = new byte[_bufferSize];
                    readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);

                    totalBytesRead += readAheadBytesRead;

                    do
                    {
                        bytesRead = readAheadBytesRead;
                        buffer = readAheadBuffer;

                        readAheadBuffer = new byte[_bufferSize];
                        readAheadBytesRead = stream.Read(readAheadBuffer, 0, readAheadBuffer.Length);

                        totalBytesRead += readAheadBytesRead;

                        if (readAheadBytesRead == 0)
                            hashAlgorithm.TransformFinalBlock(buffer, 0, bytesRead);
                        else
                            hashAlgorithm.TransformBlock(buffer, 0, bytesRead, buffer, 0);
                    } while (readAheadBytesRead != 0);
                }

                string hex = "";
                foreach (byte b in hashAlgorithm.Hash)
                    hex += b.ToString("x2");

                return hex.ToLower();
            }
            catch (Exception)
            {
                return null;
            }
        }
开发者ID:opt-io,项目名称:B2SimpleUpload,代码行数:52,代码来源:Program.cs

示例14: CalculateHash

        /// <exception cref="IOException">The underlying stream is null or closed. </exception>
        /// <exception cref="DirectoryNotFoundException">The specified path is invalid, (for example, it is on an unmapped drive). </exception>
        /// <exception cref="UnauthorizedAccessException"><paramref name="path" /> specified a directory.-or- The caller does not have the required permission. </exception>
        /// <exception cref="FileNotFoundException">The file specified in <paramref name="path" /> was not found. </exception>
        /// <exception cref="CryptographicUnexpectedOperationException"><see cref="F:System.Security.Cryptography.HashAlgorithm.HashValue" /> is null. </exception>
        /// <exception cref="ObjectDisposedException">The object has already been disposed.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="oldValue" /> is null. </exception>
        /// <exception cref="ArgumentException"><paramref name="oldValue" /> is the empty string (""). </exception>
        /// <exception cref="Exception">A delegate callback throws an exception.</exception>
        /// <exception cref="OperationCanceledException">The token has had cancellation requested.</exception>
        public string CalculateHash(string file, HashAlgorithm algorithm, CancellationToken token)
        {
            byte[] buffer;
            byte[] oldBuffer;
            int bytesRead;
            int oldBytesRead;
            long size;
            long totalBytesRead = 0;
            using (var bufferedStream = new BufferedStream(File.OpenRead(file)))
            {
                using (algorithm)
                {
                    size = bufferedStream.Length;
                    buffer = new byte[4096];
                    bytesRead = bufferedStream.Read(buffer, 0, buffer.Length);
                    totalBytesRead += bytesRead;

                    do
                    {
                        token.ThrowIfCancellationRequested();
                        oldBytesRead = bytesRead;
                        oldBuffer = buffer;

                        buffer = new byte[4096];
                        bytesRead = bufferedStream.Read(buffer, 0, buffer.Length);
                        totalBytesRead += bytesRead;

                        if (bytesRead == 0)
                        {
                            algorithm.TransformFinalBlock(oldBuffer, 0, oldBytesRead);
                        }
                        else
                        {
                            algorithm.TransformBlock(oldBuffer, 0, oldBytesRead, oldBuffer, 0);
                        }
                        HashProgressUpdate?.Invoke(this, new ProgressEventArgs((double) totalBytesRead*100/size));
                    } while (bytesRead != 0);
                    return BitConverter.ToString(algorithm.Hash).Replace("-", string.Empty).ToUpper();
                }
            }
        }
开发者ID:5oundtech,项目名称:WoblaExplorer,代码行数:51,代码来源:ChecksumCalculators.cs

示例15: DownloadNextChunk

        private int DownloadNextChunk(IDocument remoteDocument, long offset, long remainingBytes, Transmission transmission, Stream outputstream, HashAlgorithm hashAlg) {
            lock(this.disposeLock) {
                if (this.disposed) {
                    transmission.Status = TransmissionStatus.ABORTED;
                    throw new ObjectDisposedException(transmission.Path);
                }

                IContentStream contentStream = remoteDocument.GetContentStream(remoteDocument.ContentStreamId, offset, remainingBytes);
                transmission.Length = remoteDocument.ContentStreamLength;
                transmission.Position = offset;

                using (var remoteStream = contentStream.Stream)
                using (var forwardstream = new ForwardReadingStream(remoteStream))
                using (var offsetstream = new OffsetStream(forwardstream, offset))
                using (var progress = transmission.CreateStream(offsetstream)) {
                    byte[] buffer = new byte[8 * 1024];
                    int result = 0;
                    int len;
                    while ((len = progress.Read(buffer, 0, buffer.Length)) > 0) {
                        outputstream.Write(buffer, 0, len);
                        hashAlg.TransformBlock(buffer, 0, len, buffer, 0);
                        result += len;
                        outputstream.Flush();
                    }

                    return result;
                }
            }
        }
开发者ID:OpenDataSpace,项目名称:CmisSync,代码行数:29,代码来源:ChunkedDownloader.cs


注:本文中的System.Security.Cryptography.HashAlgorithm.TransformBlock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。