本文整理汇总了VB.NET中System.Security.Cryptography.HashAlgorithm.TransformFinalBlock方法的典型用法代码示例。如果您正苦于以下问题:VB.NET HashAlgorithm.TransformFinalBlock方法的具体用法?VB.NET HashAlgorithm.TransformFinalBlock怎么用?VB.NET HashAlgorithm.TransformFinalBlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了HashAlgorithm.TransformFinalBlock方法的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