本文整理汇总了VB.NET中System.Security.Cryptography.HashAlgorithm.TransformBlock方法的典型用法代码示例。如果您正苦于以下问题:VB.NET HashAlgorithm.TransformBlock方法的具体用法?VB.NET HashAlgorithm.TransformBlock怎么用?VB.NET HashAlgorithm.TransformBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了HashAlgorithm.TransformBlock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Program
' 导入命名空间
Imports System.Text
Imports System.Security.Cryptography
Class Program
Public Shared Sub Main()
Dim rnd As RandomNumberGenerator = RandomNumberGenerator.Create
Dim input() As Byte = New Byte((20) - 1) {}
rnd.GetBytes(input)
Console.WriteLine("Input : {0}"& vbLf, BytesToStr(input))
PrintHash(input)
PrintHashOneBlock(input)
PrintHashMultiBlock(input, 1)
PrintHashMultiBlock(input, 2)
PrintHashMultiBlock(input, 3)
PrintHashMultiBlock(input, 5)
PrintHashMultiBlock(input, 10)
PrintHashMultiBlock(input, 11)
PrintHashMultiBlock(input, 19)
PrintHashMultiBlock(input, 20)
PrintHashMultiBlock(input, 21)
End Sub
Public Shared Function BytesToStr(ByVal bytes() As Byte) As String
Dim str As StringBuilder = New StringBuilder
Dim i As Integer = 0
Do While (i < bytes.Length)
str.AppendFormat("{0:X2}", bytes(i))
i = (i + 1)
Loop
Return str.ToString
End Function
Public Shared Sub PrintHash(ByVal input() As Byte)
Dim sha As SHA256Managed = New SHA256Managed
Console.WriteLine("ComputeHash : {0}", BytesToStr(sha.ComputeHash(input)))
End Sub
Public Shared Sub PrintHashOneBlock(ByVal input() As Byte)
Dim sha As SHA256Managed = New SHA256Managed
sha.TransformFinalBlock(input, 0, input.Length)
Console.WriteLine("FinalBlock : {0}", BytesToStr(sha.Hash))
End Sub
Public Shared Sub PrintHashMultiBlock(ByVal input() As Byte, ByVal size As Integer)
Dim sha As SHA256Managed = New SHA256Managed
Dim offset As Integer = 0
While ((input.Length - offset) _
>= size)
offset = (offset + sha.TransformBlock(input, offset, size, input, offset))
End While
sha.TransformFinalBlock(input, offset, (input.Length - offset))
Console.WriteLine("MultiBlock {0:00}: {1}", size, BytesToStr(sha.Hash))
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System.Security.Cryptography,代码行数:58,代码来源:HashAlgorithm.TransformBlock
注:本文中的System.Security.Cryptography.HashAlgorithm.TransformBlock方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论