FrmCoder: Duplicate TextCoderBase64 for ASCII and UTF-8 support
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public interface ICoder
|
||||
public interface ITextCoder
|
||||
{
|
||||
string Encode(string input, string key);
|
||||
string Decode(string input, string key);
|
||||
@@ -3,7 +3,7 @@ using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class CoderBase64 : ICoder
|
||||
public class TextCoderBase64Ascii : ITextCoder
|
||||
{
|
||||
public string Decode(string input, string key)
|
||||
{
|
||||
26
VAR.Toolbox/Code/TextCoderBase64Utf8.cs
Normal file
26
VAR.Toolbox/Code/TextCoderBase64Utf8.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace VAR.Toolbox.Code
|
||||
{
|
||||
public class TextCoderBase64Utf8 : ITextCoder
|
||||
{
|
||||
public string Decode(string input, string key)
|
||||
{
|
||||
byte[] encodedDataAsBytes
|
||||
= Convert.FromBase64String(input);
|
||||
string returnValue =
|
||||
Encoding.UTF8.GetString(encodedDataAsBytes);
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
public string Encode(string input, string key)
|
||||
{
|
||||
byte[] toEncodeAsBytes
|
||||
= Encoding.UTF8.GetBytes(input);
|
||||
string returnValue
|
||||
= Convert.ToBase64String(toEncodeAsBytes);
|
||||
return returnValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
86
VAR.Toolbox/UI/FrmCoder.Designer.cs
generated
86
VAR.Toolbox/UI/FrmCoder.Designer.cs
generated
@@ -32,10 +32,10 @@
|
||||
this.btnDecode = new System.Windows.Forms.Button();
|
||||
this.txtOutput = new System.Windows.Forms.TextBox();
|
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||
this.btnEncode = new System.Windows.Forms.Button();
|
||||
this.cboCode = new System.Windows.Forms.ComboBox();
|
||||
this.btnSwap = new System.Windows.Forms.Button();
|
||||
this.txtKey = new System.Windows.Forms.TextBox();
|
||||
this.cboCode = new System.Windows.Forms.ComboBox();
|
||||
this.btnEncode = new System.Windows.Forms.Button();
|
||||
this.btnSwap = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
|
||||
this.splitContainer1.Panel1.SuspendLayout();
|
||||
this.splitContainer1.Panel2.SuspendLayout();
|
||||
@@ -47,21 +47,19 @@
|
||||
this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtInput.Location = new System.Drawing.Point(13, 14);
|
||||
this.txtInput.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.txtInput.Location = new System.Drawing.Point(9, 9);
|
||||
this.txtInput.Multiline = true;
|
||||
this.txtInput.Name = "txtInput";
|
||||
this.txtInput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.txtInput.Size = new System.Drawing.Size(527, 463);
|
||||
this.txtInput.Size = new System.Drawing.Size(353, 310);
|
||||
this.txtInput.TabIndex = 0;
|
||||
//
|
||||
// btnDecode
|
||||
//
|
||||
this.btnDecode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnDecode.Location = new System.Drawing.Point(219, 593);
|
||||
this.btnDecode.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnDecode.Location = new System.Drawing.Point(146, 393);
|
||||
this.btnDecode.Name = "btnDecode";
|
||||
this.btnDecode.Size = new System.Drawing.Size(94, 35);
|
||||
this.btnDecode.Size = new System.Drawing.Size(63, 23);
|
||||
this.btnDecode.TabIndex = 1;
|
||||
this.btnDecode.Text = "Decode";
|
||||
this.btnDecode.UseVisualStyleBackColor = true;
|
||||
@@ -72,13 +70,12 @@
|
||||
this.txtOutput.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtOutput.Location = new System.Drawing.Point(11, 14);
|
||||
this.txtOutput.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.txtOutput.Location = new System.Drawing.Point(7, 9);
|
||||
this.txtOutput.Multiline = true;
|
||||
this.txtOutput.Name = "txtOutput";
|
||||
this.txtOutput.ReadOnly = true;
|
||||
this.txtOutput.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.txtOutput.Size = new System.Drawing.Size(533, 558);
|
||||
this.txtOutput.Size = new System.Drawing.Size(356, 372);
|
||||
this.txtOutput.TabIndex = 2;
|
||||
//
|
||||
// splitContainer1
|
||||
@@ -87,7 +84,6 @@
|
||||
| System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.splitContainer1.Location = new System.Drawing.Point(0, 0);
|
||||
this.splitContainer1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.splitContainer1.Name = "splitContainer1";
|
||||
//
|
||||
// splitContainer1.Panel1
|
||||
@@ -102,67 +98,61 @@
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.btnSwap);
|
||||
this.splitContainer1.Panel2.Controls.Add(this.txtOutput);
|
||||
this.splitContainer1.Size = new System.Drawing.Size(1114, 643);
|
||||
this.splitContainer1.SplitterDistance = 551;
|
||||
this.splitContainer1.SplitterWidth = 6;
|
||||
this.splitContainer1.Size = new System.Drawing.Size(743, 426);
|
||||
this.splitContainer1.SplitterDistance = 367;
|
||||
this.splitContainer1.TabIndex = 3;
|
||||
//
|
||||
// btnEncode
|
||||
// txtKey
|
||||
//
|
||||
this.btnEncode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnEncode.Location = new System.Drawing.Point(321, 593);
|
||||
this.btnEncode.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnEncode.Name = "btnEncode";
|
||||
this.btnEncode.Size = new System.Drawing.Size(94, 35);
|
||||
this.btnEncode.TabIndex = 3;
|
||||
this.btnEncode.Text = "Encode";
|
||||
this.btnEncode.UseVisualStyleBackColor = true;
|
||||
this.btnEncode.Click += new System.EventHandler(this.btnEncodeBase64_Click);
|
||||
this.txtKey.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtKey.Location = new System.Drawing.Point(9, 325);
|
||||
this.txtKey.Multiline = true;
|
||||
this.txtKey.Name = "txtKey";
|
||||
this.txtKey.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.txtKey.Size = new System.Drawing.Size(353, 59);
|
||||
this.txtKey.TabIndex = 5;
|
||||
//
|
||||
// cboCode
|
||||
//
|
||||
this.cboCode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.cboCode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.cboCode.FormattingEnabled = true;
|
||||
this.cboCode.Items.AddRange(new object[] {
|
||||
"Base64"});
|
||||
this.cboCode.Location = new System.Drawing.Point(18, 597);
|
||||
this.cboCode.Location = new System.Drawing.Point(12, 396);
|
||||
this.cboCode.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
|
||||
this.cboCode.Name = "cboCode";
|
||||
this.cboCode.Size = new System.Drawing.Size(194, 28);
|
||||
this.cboCode.Size = new System.Drawing.Size(131, 21);
|
||||
this.cboCode.TabIndex = 4;
|
||||
this.cboCode.SelectedIndexChanged += new System.EventHandler(this.cboCode_SelectedIndexChanged);
|
||||
//
|
||||
// btnEncode
|
||||
//
|
||||
this.btnEncode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnEncode.Location = new System.Drawing.Point(214, 393);
|
||||
this.btnEncode.Name = "btnEncode";
|
||||
this.btnEncode.Size = new System.Drawing.Size(63, 23);
|
||||
this.btnEncode.TabIndex = 3;
|
||||
this.btnEncode.Text = "Encode";
|
||||
this.btnEncode.UseVisualStyleBackColor = true;
|
||||
this.btnEncode.Click += new System.EventHandler(this.btnEncodeBase64_Click);
|
||||
//
|
||||
// btnSwap
|
||||
//
|
||||
this.btnSwap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
|
||||
this.btnSwap.Location = new System.Drawing.Point(4, 593);
|
||||
this.btnSwap.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.btnSwap.Location = new System.Drawing.Point(3, 393);
|
||||
this.btnSwap.Name = "btnSwap";
|
||||
this.btnSwap.Size = new System.Drawing.Size(94, 35);
|
||||
this.btnSwap.Size = new System.Drawing.Size(63, 23);
|
||||
this.btnSwap.TabIndex = 4;
|
||||
this.btnSwap.Text = "Swap";
|
||||
this.btnSwap.UseVisualStyleBackColor = true;
|
||||
this.btnSwap.Click += new System.EventHandler(this.btnSwap_Click);
|
||||
//
|
||||
// txtKey
|
||||
//
|
||||
this.txtKey.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
|
||||
| System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.txtKey.Location = new System.Drawing.Point(13, 487);
|
||||
this.txtKey.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.txtKey.Multiline = true;
|
||||
this.txtKey.Name = "txtKey";
|
||||
this.txtKey.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
|
||||
this.txtKey.Size = new System.Drawing.Size(527, 89);
|
||||
this.txtKey.TabIndex = 5;
|
||||
//
|
||||
// FrmCoder
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1114, 642);
|
||||
this.ClientSize = new System.Drawing.Size(743, 425);
|
||||
this.Controls.Add(this.splitContainer1);
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.Name = "FrmCoder";
|
||||
this.Text = "Coder";
|
||||
this.splitContainer1.Panel1.ResumeLayout(false);
|
||||
|
||||
@@ -10,11 +10,14 @@ namespace VAR.Toolbox.UI
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
cboCode.SelectedItem = "Base64";
|
||||
cboCode.Items.Add("Base64Ascii");
|
||||
cboCode.Items.Add("Base64Utf8");
|
||||
|
||||
cboCode.SelectedItem = "Base64Ascii";
|
||||
|
||||
}
|
||||
|
||||
private ICoder _coder = null;
|
||||
private ITextCoder _coder = null;
|
||||
|
||||
private void btnDecodeBase64_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -54,10 +57,16 @@ namespace VAR.Toolbox.UI
|
||||
private void cboCode_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
string code = (string)cboCode.SelectedItem;
|
||||
if(code == "Base64")
|
||||
if(code == "Base64Ascii")
|
||||
{
|
||||
txtKey.Enabled = false;
|
||||
_coder = new CoderBase64();
|
||||
_coder = new TextCoderBase64Ascii();
|
||||
return;
|
||||
}
|
||||
if (code == "Base64Utf8")
|
||||
{
|
||||
txtKey.Enabled = false;
|
||||
_coder = new TextCoderBase64Utf8();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
120
VAR.Toolbox/UI/FrmCoder.resx
Normal file
120
VAR.Toolbox/UI/FrmCoder.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -53,7 +53,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Code\CoderBase64.cs" />
|
||||
<Compile Include="Code\TextCoderBase64Utf8.cs" />
|
||||
<Compile Include="Code\TextCoderBase64Ascii.cs" />
|
||||
<Compile Include="Code\DirectShow\CameraControlProperty.cs" />
|
||||
<Compile Include="Code\DirectShow\IAMCameraControl.cs" />
|
||||
<Compile Include="Code\DirectShow\IAMCrossbar.cs" />
|
||||
@@ -85,7 +86,7 @@
|
||||
<Compile Include="Code\DirectShow\Uuids.cs" />
|
||||
<Compile Include="Code\DirectShow\Win32.cs" />
|
||||
<Compile Include="Code\GDI32.cs" />
|
||||
<Compile Include="Code\ICoder.cs" />
|
||||
<Compile Include="Code\ITextCoder.cs" />
|
||||
<Compile Include="Code\IOutputHandler.cs" />
|
||||
<Compile Include="Code\IProxyCmdExecutor.cs" />
|
||||
<Compile Include="Code\Logger.cs" />
|
||||
@@ -191,6 +192,11 @@
|
||||
<Content Include="Images\toolbox.svg" />
|
||||
<Content Include="Toolbox.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="UI\FrmCoder.resx">
|
||||
<DependentUpon>FrmCoder.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
||||
Reference in New Issue
Block a user