Ejemplo para convertir un String a Base64 y pasar de Base64 a String
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
DotNetcr.String2Base64
.gitattributes
.gitignore
DotNetcr.String2Base64.sln
README.md

README.md

String2Base64

Ejemplo para convertir un texto a Base64 y convertir Base64 a texto. En la solución está el ejemplo de como usarlo.

C#

    /// <summary>
    /// Convierte string en Base64 a texto
    /// </summary>
    /// <param name="valor">Valor a reemplazar</param>
    /// <returns></returns>
    public static string DecodeBase64ToString(string valor)
    {
        byte[] myBase64ret = Convert.FromBase64String(valor);
        string myStr = System.Text.Encoding.UTF8.GetString(myBase64ret);
        return myStr;
    }

    /// <summary>
    /// Convierte texto string en Base64
    /// </summary>
    /// <param name="valor">Valor a reemplazar</param>
    /// <returns></returns>
    public static string EncodeStrToBase64(string valor)
    {
        byte[] myByte = System.Text.Encoding.UTF8.GetBytes(valor);
        string myBase64 = Convert.ToBase64String(myByte);
        return myBase64;
    }

VB

Public Shared Function DecodeBase64ToString(valor As String) As String
    Dim myBase64ret As Byte() = Convert.FromBase64String(valor)
    Dim myStr As String = System.Text.Encoding.UTF8.GetString(myBase64ret)
    Return myStr
End Function

Public Shared Function EncodeStrToBase64(valor As String) As String
    Dim myByte As Byte() = System.Text.Encoding.UTF8.GetBytes(valor)
    Dim myBase64 As String = Convert.ToBase64String(myByte)
    Return myBase64
End Function