Base64 Converter

<Window x:Class="Base64Convertor.MainWindow"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

Title="MainWindow" Height="387" Width="629">

<Grid>

<Grid.RowDefinitions>

<RowDefinition/>

<RowDefinition Height="auto"/>

<RowDefinition/>

</Grid.RowDefinitions>

<GroupBox Grid.Row="0" Header="Input" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="groupBox1" VerticalAlignment="Stretch">

<TextBox Name="txtInput" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Yellow" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" />

</GroupBox>

?

<TabControl Grid.Row="1">

<TabItem Header="Encode" >

<StackPanel Grid.Row="1" Orientation="Horizontal">

<Button Name="btnEncodeInputText" Content="From Input Text" Height="25" Margin="5" Click="btnEncodeInputText_Click" />

<Button Name="btnEncodeInputFile" Content="From Input File" Height="25" Margin="5" Click="btnEncodeInputFile_Click" />

<Button Name="btnCopyToClipboard" Content="Copy to Clipboard" Height="25" Margin="5" Click="btnCopyToClipboard_Click" />

</StackPanel>

</TabItem>

<TabItem Header="Decode">

<StackPanel Grid.Row="1" Orientation="Horizontal">

<Button Name="btnDecodeToOutput" Content="Decode to Output" Margin="5" Height="25" Click="btnDecodeToOutput_Click" />

<Button Name="btnDecodeToFile" Content="Decode to File" Height="25" Margin="5" Click="btnDecodeToFile_Click" />

</StackPanel>

</TabItem>

</TabControl>

?

<GroupBox Grid.Row="2" Header="Output" HorizontalAlignment="Stretch" Margin="0,0,0,0" Name="groupBox2" VerticalAlignment="Stretch">

<TextBox Name="txtOutput" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Yellow" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" AcceptsReturn="True" />

</GroupBox>

</Grid>

</Window>

?

public
partial
class
MainWindow : Window

{

public MainWindow()

{

InitializeComponent();

}

?

private
void btnEncodeInputText_Click(object sender, RoutedEventArgs e)

{

txtOutput.Text = Convert.ToBase64String(Encoding.UTF8.GetBytes(txtInput.Text.Trim()));

}

?

private
void btnDecodeToOutput_Click(object sender, RoutedEventArgs e)

{

txtOutput.Text = Encoding.UTF8.GetString(Convert.FromBase64String(txtInput.Text.Trim()));

}

?

private
void btnEncodeInputFile_Click(object sender, RoutedEventArgs e)

{

OpenFileDialog ofd = new
OpenFileDialog();

if (ofd.ShowDialog().Value == true)

{

var fileContent = File.ReadAllBytes(ofd.FileName);

txtOutput.Text = Convert.ToBase64String(fileContent);

MessageBox.Show("done!");

}

}

?

private
void btnCopyToClipboard_Click(object sender, RoutedEventArgs e)

{

Clipboard.SetText(txtOutput.Text);

}

?

private
void btnDecodeToFile_Click(object sender, RoutedEventArgs e)

{

SaveFileDialog sfd = new
SaveFileDialog();

if (sfd.ShowDialog().Value == true)

{

var fileContent = Convert.FromBase64String(txtInput.Text.Trim());

File.WriteAllBytes(sfd.FileName, fileContent);

MessageBox.Show("done!");

}

}

}

时间: 2024-07-28 20:18:24

Base64 Converter的相关文章

gulp教程(sass,livereload,md5,css压缩,js压缩,img的base64)

环境 node -v  v6.10.3 npm -v  3.10.10 package.json如下: { "name": "zhcsdata", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": &

PHP_EOL换行 与 base64编码

base64编码包括64个字符:10个数字(0-9),26*2个字母(a-zA-Z),+,\ 其中还有一个第65个字符=作为后缀,没有实际作用. 来一段代码说明个问题: 1 <?php 2 3 $str = '1234567'; 4 5 $en = base64_encode($str);// MTIzNDU2Nw== 6 7 $en = 'MTIzND U 8 9 2Nw=========='; 10 11 echo base64_decode($en);// 1234567 可以看到,即使修

[C语言]Base64编码解码

Base64编码解码 一,Base64编码原理 Base64编码的字符数组如下所示 : ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ 字符串转Base64编码:取3字节的字符串转换为四字节的字符串,依次往后转换.得到Base64编码字符串.具体原理如下: 1,如果需要编码的原串字节数刚好为3的倍数,那么转换规则如下: 以中文字符'严'为例,'严'字的UTF-8编码为:0xE4B8A5 = 11100100  10

Dozer 自定义Converter -- LocalDateTime to Date

Spring boot项目,使用dozer将Jpa Entity中的LocalDateTime属性转到DTO中对应的LocalDateTime属性中报错 java.lang.NoSuchMethodException: java.time.LocalDateTime.<init>() at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_51] at java.lang.Class.getDeclaredConstruct

【前端攻略】:玩转图片Base64编码(转)

引言 图片处理在前端工作中可谓占据了很重要的一壁江山.而图片的Base64编码可能相对一些人而言比较陌生,本文不是从纯技术的角度去讨论图片的base64编码.标题略大,不过只是希望通过一些浅显的论述,让你知道什么是图片的base64编码,为什么我们要用它,我们如何使用并且方便的使用它,并让你懂得如何去在前端的实际工作中运用它. 什么是base64编码? 我不是来讲概念的,直接切入正题,图片的base64编码就是可以将一副图片数据编码成一串字符串,使用该字符串代替图像地址. 这样做有什么意义呢?我

base64 编码

转载自网络 (一)java自带的加密和解密 import sun.misc.BASE64Decoder; public class Base64Utils {  public static String getBASE64(byte[] b) {  String s = null;  if (b != null) {   s = new sun.misc.BASE64Encoder().encode(b);  }  return s; }  public static byte[] getFro

使用HTML5的File实现base64和图片的互转

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

PDF编辑工具——PDF Desktop Converter 4 Professional

管理和操作PDF的工具.PDF Desktop Converter 4 Professional可以生成,转换,提取,组合,分割合并PDF.新增加的OCR功能可以将扫描后的文件转变成可以检索和编辑的PDF.以上这些功能只需要一个软件就可以全部实现. 软件特点 1. 快速,准确,简单的生成PDF. * Add-in按钮 -从Microsoft应用程序立即生成PDF -无需Microsoft应用程序,可以立即将PDF转换成Word,Excel. * 采用密码对PDF文件中的敏感信息进行控制,限制浏览

PHP base64数据与图片的互相转换

1.解析base64数据成图片 The problem is that data:image/bmp;base64, is included in the encoded contents. This will result in invalid image data when the base64 function decodes it. Remove that data in the function before decoding the string, like so. $base64