本文整理汇总了VB.NET中System.Convert.FromBase64String方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Convert.FromBase64String方法的具体用法?VB.NET Convert.FromBase64String怎么用?VB.NET Convert.FromBase64String使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Convert
的用法示例。
在下文中一共展示了Convert.FromBase64String方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
Module Example
Public Sub Main()
' Define a byte array.
Dim bytes As Byte() = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }
Console.WriteLine("The byte array: ")
Console.WriteLine(" {0}", BitConverter.ToString(bytes))
Console.WriteLine()
' Convert the array to a base 64 string.
Dim s As String = Convert.ToBase64String(bytes)
Console.WriteLine("The base 64 string:{1} {0}{1}",
s, vbCrLf)
' Restore the byte array.
Dim newBytes As Byte() = Convert.FromBase64String(s)
Console.WriteLine("The restored byte array: ")
Console.WriteLine(" {0}", BitConverter.ToString(newBytes))
Console.WriteLine()
End Sub
End Module
输出:
The byte array: 02-04-06-08-0A-0C-0E-10-12-14 The base 64 string: AgQGCAoMDhASFA== The restored byte array: 02-04-06-08-0A-0C-0E-10-12-14
示例2: Example
Module Example
Public Sub Main()
' Define an array of 20 elements and display it.
Dim arr(19) As Integer
Dim value As Integer = 1
For ctr As Integer = 0 To arr.GetUpperBound(0)
arr(ctr) = value
value = value * 2 + 1
Next
DisplayArray(arr)
' Convert the array of integers to a byte array.
Dim bytes(arr.Length * 4 - 1) As Byte
For ctr As Integer = 0 To arr.Length - 1
Array.Copy(BitConverter.GetBytes(arr(ctr)), 0,
bytes, ctr * 4, 4)
Next
' Encode the byte array using Base64 encoding
Dim base64 As String = Convert.ToBase64String(bytes)
Console.WriteLine("The encoded string: ")
For ctr As Integer = 0 To base64.Length \ 50 - 1
Console.WriteLine(base64.Substring(ctr * 50,
If(ctr * 50 + 50 <= base64.Length,
50, base64.Length - ctr * 50)))
Next
Console.WriteLine()
' Convert the string back to a byte array.
Dim newBytes() As Byte = Convert.FromBase64String(base64)
' Convert the byte array back to an integer array.
Dim newArr(newBytes.Length\4 - 1) As Integer
For ctr As Integer = 0 To newBytes.Length \ 4 - 1
newArr(ctr) = BitConverter.ToInt32(newBytes, ctr * 4)
Next
DisplayArray(newArr)
End Sub
Private Sub DisplayArray(arr As Array)
Console.WriteLine("The array:")
Console.Write("{ ")
For ctr As Integer = 0 To arr.GetUpperBound(0) - 1
Console.Write("{0}, ", arr.GetValue(ctr))
If (ctr + 1) Mod 10 = 0 Then Console.Write("{0} ", vbCrLf)
Next
Console.WriteLine("{0} {1}", arr.GetValue(arr.GetUpperBound(0)), "}")
Console.WriteLine()
End Sub
End Module
输出:
The array: { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575 } The encoded string: AQAAAAMAAAAHAAAADwAAAB8AAAA/AAAAfwAAAP8AAAD/AQAA/w MAAP8HAAD/DwAA/x8AAP8/AAD/fwAA//8AAP//AQD//wMA//8H The array: { 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 131071, 262143, 524287, 1048575 }
示例3: Tester
Public Class Tester
Public Shared Sub Main
Dim quote As String = "AAAAA"
Dim quoteBytes As Byte() = System.Text.Encoding.UTF8.GetBytes(quote)
Dim quote64 As String = Convert.ToBase64String(quoteBytes)
Dim byteSet As Byte() = Convert.FromBase64String(quote64)
Dim result As String = System.Text.Encoding.UTF8.GetString(byteSet)
Console.WriteLine(quote & vbNewLine & quote64 & vbNewLine & result)
End Sub
End Class