ExtensionMethod.NET Home of 817 C#, Visual Basic, F# and Javascript extension methods

ToBase64 / FromBase64

Convert string to/from Base64 encodeing

Source

<Extension()> _
Public Function ToBase64(ByVal value As String) As String
    If String.IsNullOrEmpty(value) Then
        Return value
    Else
        Dim encoding As New System.Text.ASCIIEncoding()
        Return Convert.ToBase64String(encoding.GetBytes(value))
    End If
End Function

<Extension()> _
Public Function FromBase64(ByVal value As String) As String
    If String.IsNullOrEmpty(value) Then
        Return value
    Else
        Dim encoding As New System.Text.ASCIIEncoding()
        Return encoding.GetString(Convert.FromBase64String(value))
    End If
End Function

Example

Textbox1.Text.ToBase64

db.Password.FromBase64

Author: NetDorkie

Submitted on: 16 jul 2009

Language: VB

Type: System.String

Views: 2900