Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Encryption for pairing
Browse files Browse the repository at this point in the history
  • Loading branch information
xfoxfu committed Jun 13, 2015
1 parent 0a89409 commit 23345bd
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Auth/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.9")]
[assembly: AssemblyFileVersion("1.1.0.9")]
[assembly: AssemblyVersion("1.1.0.12")]
[assembly: AssemblyFileVersion("1.1.0.12")]
4 changes: 2 additions & 2 deletions Configure/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.5")]
[assembly: AssemblyVersion("1.1.0.5")]
[assembly: AssemblyFileVersion("1.1.0.5")]
17 changes: 15 additions & 2 deletions Configure/Setter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ private async void okButton_Click(object sender, EventArgs e)
tcpClient.Connect(this.pi.IP, NetworkPorts.Pair);
using (var tcpStreamWriter = new StreamWriter(tcpClient.GetStream(), Encodes.UTF8NoBOM))
{
await tcpStreamWriter.WriteLineAsync(Crypt.Encrypt("PAIR" + this.passBox.Text));
await tcpStreamWriter.WriteLineAsync(Encrypt("PAIR" + this.passBox.Text));
await tcpStreamWriter.FlushAsync();
using (var tcpStreamReader = new StreamReader(tcpClient.GetStream(), Encodes.UTF8NoBOM))
{
// handle result
string result = Crypt.Decrypt(await tcpStreamReader.ReadLineAsync());
string result = Decrypt(await tcpStreamReader.ReadLineAsync());
if (result == "PAIROK" + this.passBox.Text)
{
this.statusLabel.Text = "配对成功,正在等待密钥交换!";
// handle key
this.key = Decrypt(await tcpStreamReader.ReadLineAsync());
WriteConfig();
}
else if (result == "PAIRFAIL" + this.passBox.Text)
Expand All @@ -63,9 +65,20 @@ private void WriteConfig()
var sWriter = new System.IO.StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "/pair");
sWriter.WriteLine(Crypt.Encrypt(this.pi.StorgeString));
sWriter.WriteLine(Crypt.Encrypt(this.passBox.Text));
sWriter.WriteLine(Crypt.Encrypt(this.key));
sWriter.Close();
sWriter.Dispose();
Application.ExitThread();
}

private string Encrypt(string message)
{
return Crypt.Encrypt(message, Crypt.GeneratePairKey());
}

private string Decrypt(string cipherText)
{
return Crypt.Decrypt(cipherText, Crypt.GeneratePairKey());
}
}
}
9 changes: 9 additions & 0 deletions CryptionDebugger/CryptionDebugger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RollingKey.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="RollingKey.Designer.cs">
<DependentUpon>RollingKey.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Main.resx">
<DependentUpon>Main.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -66,6 +72,9 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="RollingKey.resx">
<DependentUpon>RollingKey.cs</DependentUpon>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
17 changes: 15 additions & 2 deletions CryptionDebugger/Main.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion CryptionDebugger/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using System.Windows.Forms;
using RapID.ClassLibrary;

namespace RapID.Debug.Cryption
namespace RapID.CryptionDebugger
{
public partial class Main : Form
{
Expand All @@ -27,5 +27,11 @@ private void decryptButton_Click(object sender, EventArgs e)
{
sourceTextBox.Text = Crypt.Decrypt(cipherTextBox.Text);
}

private void showRollingKeyFormButton_Click(object sender, EventArgs e)
{
var frm = new RollingKey();
frm.ShowDialog();
}
}
}
2 changes: 1 addition & 1 deletion CryptionDebugger/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RapID.Debug.Cryption
namespace RapID.CryptionDebugger
{
static class Program
{
Expand Down
4 changes: 2 additions & 2 deletions CryptionDebugger/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.3")]
[assembly: AssemblyFileVersion("1.0.0.3")]
[assembly: AssemblyVersion("1.1.0.8")]
[assembly: AssemblyFileVersion("1.1.0.8")]
105 changes: 105 additions & 0 deletions CryptionDebugger/RollingKey.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions CryptionDebugger/RollingKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using RapID.ClassLibrary;

namespace RapID.CryptionDebugger
{
public partial class RollingKey : Form
{
public RollingKey()
{
InitializeComponent();
}

private void encryptButton_Click(object sender, EventArgs e)
{
this.cipherTextBox.Text = Crypt.Encrypt(this.sourceTextBox.Text, Crypt.GenerateKey(this.originalKeyBox.Text));
}

private void decryptButton_Click(object sender, EventArgs e)
{
this.sourceTextBox.Text = Crypt.Encrypt(this.cipherTextBox.Text, Crypt.GenerateKey(this.originalKeyBox.Text));
}
}
}
Loading

0 comments on commit 23345bd

Please sign in to comment.