首页  编辑  

Base64编码处理

Tags: /C#/字符串处理/   Date Created:

private void button1_Click( object sender , EventArgs e)

{

    string vSourceStr = "Zswang ;

    byte [] vSourceBytes = Encoding . Default . GetBytes(vSourceStr);

    string vBase64Str = Convert . ToBase64String(vSourceBytes);

    MessageBox . Show(vBase64Str);

    byte [] vDestBytes = Convert . FromBase64String(vBase64Str);

    string vUtf8Str = Encoding . Default . GetString(vDestBytes);

    MessageBox . Show(vUtf8Str);

}

// or ------------

public static string Base64Encode( string AStr )

{

    return Convert . ToBase64String( ASCIIEncoding . Default . GetBytes(AStr));

}

public static string Base64Decode( string ABase64 )

{

    return ASCIIEncoding . Default . GetString( Convert . FromBase64String(ABase64));

}

private void button1_Click( object sender , EventArgs e)

{

   Text = Base64Decode(Base64Encode( "Zswang ));

}