処理の作成

This commit is contained in:
koujiri committed 2023-09-28 17:41:28 +09:00
1 parent 409975baad
commit 5751bc7ea7
8 files changed
+242 -50

No files matched your search

-39
View File
@@ -1,39 +0,0 @@
namespace CryptoStringSHA
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Text = "Form1";
}
#endregion
}
}
-10
View File
@@ -1,10 +0,0 @@
namespace CryptoStringSHA
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
+169
View File
@@ -0,0 +1,169 @@
namespace CryptoStringSHA
{
partial class FrmMain
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
txtFrom = new TextBox();
txtTo = new TextBox();
btnRun = new Button();
rdoUp = new RadioButton();
rdoDown = new RadioButton();
rdo512 = new RadioButton();
rdo256 = new RadioButton();
grpRadio1 = new GroupBox();
groupBox1 = new GroupBox();
grpRadio1.SuspendLayout();
groupBox1.SuspendLayout();
SuspendLayout();
//
// txtFrom
//
txtFrom.Location = new Point(12, 12);
txtFrom.Name = "txtFrom";
txtFrom.Size = new Size(575, 23);
txtFrom.TabIndex = 0;
//
// txtTo
//
txtTo.Location = new Point(12, 226);
txtTo.Name = "txtTo";
txtTo.Size = new Size(575, 23);
txtTo.TabIndex = 1;
//
// btnRun
//
btnRun.Location = new Point(37, 99);
btnRun.Name = "btnRun";
btnRun.Size = new Size(75, 63);
btnRun.TabIndex = 2;
btnRun.Text = "↓";
btnRun.UseVisualStyleBackColor = true;
btnRun.Click += btnRun_Click;
//
// rdoUp
//
rdoUp.AutoSize = true;
rdoUp.Checked = true;
rdoUp.Location = new Point(22, 31);
rdoUp.Name = "rdoUp";
rdoUp.Size = new Size(73, 20);
rdoUp.TabIndex = 3;
rdoUp.TabStop = true;
rdoUp.Text = "大文字";
rdoUp.UseVisualStyleBackColor = true;
//
// rdoDown
//
rdoDown.AutoSize = true;
rdoDown.Location = new Point(22, 62);
rdoDown.Name = "rdoDown";
rdoDown.Size = new Size(73, 20);
rdoDown.TabIndex = 4;
rdoDown.TabStop = true;
rdoDown.Text = "小文字";
rdoDown.UseVisualStyleBackColor = true;
//
// rdo512
//
rdo512.AutoSize = true;
rdo512.Location = new Point(18, 62);
rdo512.Name = "rdo512";
rdo512.Size = new Size(73, 20);
rdo512.TabIndex = 6;
rdo512.TabStop = true;
rdo512.Text = "SHA512";
rdo512.UseVisualStyleBackColor = true;
//
// rdo256
//
rdo256.AutoSize = true;
rdo256.Checked = true;
rdo256.Location = new Point(18, 31);
rdo256.Name = "rdo256";
rdo256.Size = new Size(73, 20);
rdo256.TabIndex = 5;
rdo256.TabStop = true;
rdo256.Text = "SHA256";
rdo256.UseVisualStyleBackColor = true;
//
// grpRadio1
//
grpRadio1.Controls.Add(rdoUp);
grpRadio1.Controls.Add(rdoDown);
grpRadio1.Location = new Point(145, 77);
grpRadio1.Name = "grpRadio1";
grpRadio1.Size = new Size(120, 105);
grpRadio1.TabIndex = 7;
grpRadio1.TabStop = false;
grpRadio1.Text = "出力文字列";
//
// groupBox1
//
groupBox1.Controls.Add(rdo256);
groupBox1.Controls.Add(rdo512);
groupBox1.Location = new Point(308, 77);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(110, 105);
groupBox1.TabIndex = 8;
groupBox1.TabStop = false;
groupBox1.Text = "暗号化方法";
//
// FrmMain
//
ClientSize = new Size(599, 261);
Controls.Add(groupBox1);
Controls.Add(grpRadio1);
Controls.Add(btnRun);
Controls.Add(txtTo);
Controls.Add(txtFrom);
Font = new Font("MS ゴシック", 12F, FontStyle.Regular, GraphicsUnit.Point);
MaximumSize = new Size(615, 300);
MinimumSize = new Size(615, 300);
Name = "FrmMain";
Text = "ハッシュ関数(SHA512)を使用してハッシュ値を計算";
grpRadio1.ResumeLayout(false);
grpRadio1.PerformLayout();
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
private TextBox txtFrom;
private TextBox txtTo;
private Button btnRun;
private RadioButton rdoUp;
private RadioButton rdoDown;
private RadioButton rdo512;
private RadioButton rdo256;
private GroupBox grpRadio1;
private GroupBox groupBox1;
}
}
+34
View File
@@ -0,0 +1,34 @@
using System.Security.Cryptography;
using System.Text;
namespace CryptoStringSHA
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
private void btnRun_Click(object sender, EventArgs e)
{
txtTo.Text = rdo256.Checked ? txtFrom.Text.CryptoSHA256(rdoUp.Checked) : txtFrom.Text.CryptoSHA512(rdoUp.Checked);
}
}
public static class StringExtensions
{
static readonly HashAlgorithm hashAlgorithm256 = SHA256.Create();
static readonly HashAlgorithm hashAlgorithm512 = SHA512.Create();
public static string CryptoSHA256(this string value, bool upperFlg)
{
//16 進文字列を大文字にしたい場合は $"{x:x2}" を $"{x:X2}" と変えれば OK です。
return string.Join("", hashAlgorithm256.ComputeHash(Encoding.ASCII.GetBytes(value)).Select(x => upperFlg ? $"{x:X2}" : $"{x:x2}"));
}
public static string CryptoSHA512(this string value, bool upperFlg)
{
//16 進文字列を大文字にしたい場合は $"{x:x2}" を $"{x:X2}" と変えれば OK です。
return string.Join("", hashAlgorithm512.ComputeHash(Encoding.ASCII.GetBytes(value)).Select(x => upperFlg ? $"{x:X2}" : $"{x:x2}"));
}
}
}
File renamed without changes.
+1 -1
View File
@@ -11,7 +11,7 @@ namespace CryptoStringSHA
// To customize application configuration such as set high DPI settings or default font, // To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new Form1()); Application.Run(new FrmMain());
} }
} }
} }
@@ -0,0 +1,23 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"CryptoStringSHA/1.0.0": {
"runtime": {
"CryptoStringSHA.dll": {}
}
}
}
},
"libraries": {
"CryptoStringSHA/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
}
}
}
@@ -0,0 +1,15 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.WindowsDesktop.App",
"version": "6.0.0"
}
]
}
}