using smaller keys sha256sums finally match

* sign/verify routine worked out (shout-out to js)
This commit is contained in:
citizen 2019-12-18 13:44:57 +01:00
parent a6946d3069
commit a9c7f0b04d
Signed by: wanderer
GPG Key ID: A6FA3CA298BA2223
5 changed files with 113 additions and 3 deletions

4
Form1.Designer.cs generated
View File

@ -120,7 +120,7 @@
// richTextBox2
//
this.richTextBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.richTextBox2.Location = new System.Drawing.Point(12, 310);
this.richTextBox2.Location = new System.Drawing.Point(12, 309);
this.richTextBox2.Name = "richTextBox2";
this.richTextBox2.ReadOnly = true;
this.richTextBox2.Size = new System.Drawing.Size(437, 55);
@ -153,6 +153,7 @@
this.button6.TabIndex = 13;
this.button6.Text = "sign";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
@ -162,6 +163,7 @@
this.button7.TabIndex = 14;
this.button7.Text = "verify";
this.button7.UseVisualStyleBackColor = true;
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// textBox3
//

109
Form1.cs
View File

@ -6,6 +6,7 @@ using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
@ -51,6 +52,23 @@ namespace KRY_0x04
return metrics;
}
BigInteger return_bigint_representation_of_message(string input)
{
byte[] part_of_message = Encoding.ASCII.GetBytes(input);
return new BigInteger(part_of_message);
}
string return_string_representation_of_bigint(BigInteger bA_number)
{
byte[] decrypted_b_a = bA_number.ToByteArray();
string decrypted_text = "";
for (int i = 0; i <decrypted_b_a.Length; i++)
{
decrypted_text += Convert.ToString(Convert.ToChar(decrypted_b_a[i]));
}
return decrypted_text;
}
private void button1_Click(object sender, EventArgs e)
{
/* load msg */
@ -263,10 +281,97 @@ namespace KRY_0x04
{
MessageBox.Show("error: " + exc.ToString(), "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button6_Click(object sender, EventArgs e)
{
/* sign */
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string[] keys = richTextBox2.Text.Split(' ');
MessageBox.Show("we good?");
Console.WriteLine(BigInteger.Parse(keys[1]));
Console.WriteLine(BigInteger.Parse(keys[0]));
string signed = Convert.ToString(BigInteger.ModPow(return_bigint_representation_of_message(textBox3.Text),BigInteger.Parse(keys[1]),BigInteger.Parse(keys[0])));
saveFileDialog1.Title = ".sign";
saveFileDialog1.CheckFileExists = false;
saveFileDialog1.CheckPathExists = false;
saveFileDialog1.DefaultExt = "";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
File.WriteAllText(saveFileDialog1.FileName, signed);
MessageBox.Show($"saved to {saveFileDialog1.FileName}", "gj, file saved!", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show("error: " + ex.ToString(), "this didn't work...", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button7_Click(object sender, EventArgs e)
{
/* verify */
string[] keys = richTextBox3.Text.Split(' ');
string verified = "";
string orig_message = "";
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "pick a .sign file";
/* freedom for all */
dlg.Filter = "sign file (*.sign)|*.sign|custom (*.*)|*.*";
MessageBox.Show("we still good");
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
verified = return_string_representation_of_bigint(BigInteger.ModPow(BigInteger.Parse(File.ReadAllText(dlg.FileName)), BigInteger.Parse(keys[1]), BigInteger.Parse(keys[0])));
}
catch (Exception excep)
{
MessageBox.Show("error: " + excep.ToString(), "this didn't work...", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = "pick a .msg file";
/* freedom for all */
dlg.Filter = "msg file (*.msg)|*.msg|custom (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
try
{
orig_message = dlg.FileName;
}
catch (Exception excep)
{
MessageBox.Show("error: " + excep.ToString(), "this didn't work...", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
if (sha256sum(orig_message) == verified)
{
MessageBox.Show($"{sha256sum(orig_message)} == {verified}", "we good");
}
else
{
Console.WriteLine($"orig message: {orig_message}");
Console.WriteLine($"verif message: {verified}");
MessageBox.Show("something is seriously wrong", "checksums differ!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}

View File

@ -36,6 +36,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />

1
dsa1024.pri Normal file

File diff suppressed because one or more lines are too long

1
dsa1024.pub Normal file

File diff suppressed because one or more lines are too long