Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
naja komm,also auf dem kopf bin ich nicht gefallen,ich meinte eher ob der buchstabe "r" eine besondere bedeutung hat.
using System;
using System.Linq;
using System.Windows.Forms;
namespace TrippleDesPlayground
{
public class Form1 : Form
{
private System.IO.Stream keyfile, inFile, outFile, ivFile;
public Form1()
{
InitializeComponent();
comboBox1.Items.AddRange(Enum.GetValues(typeof(System.Security.Cryptography.CipherMode)).Cast<object>().ToArray());
comboBox1.SelectedItem = System.Security.Cryptography.CipherMode.ECB;
}
private void button2_Click(object sender, EventArgs e)
{
try
{
openKeyFile();
openInputFile();
openOutputFile();
if (inFile != null && outFile != null && keyfile != null)
encrypt();
}
finally
{
cleanup();
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
openKeyFile();
openInputFile();
openOutputFile();
if (inFile != null && outFile != null && keyfile != null)
decrypt();
}
finally
{
cleanup();
}
}
private void encrypt()
{
var csp = PrepCsp();
var cs = new System.Security.Cryptography.CryptoStream(outFile, csp.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
doCrypto(cs);
}
private void decrypt()
{
var csp = PrepCsp();
var cs = new System.Security.Cryptography.CryptoStream(outFile, csp.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
doCrypto(cs);
}
private void doCrypto(System.Security.Cryptography.CryptoStream cs)
{
inFile.CopyTo(cs);
cs.FlushFinalBlock();
}
private System.Security.Cryptography.TripleDESCryptoServiceProvider PrepCsp()
{
var csp = new System.Security.Cryptography.TripleDESCryptoServiceProvider();
var key = new Byte[Math.Min((int)csp.KeySize / 8, (int)keyfile.Length)];
keyfile.Read(key, 0, key.Length);
csp.Key = key;
csp.Mode = (System.Security.Cryptography.CipherMode)comboBox1.SelectedItem;
switch (csp.Mode)
{
case System.Security.Cryptography.CipherMode.ECB:
break;
default:
openIvFile();
csp.IV = new Byte[Math.Min((int)csp.BlockSize / 8, (int)ivFile.Length)];
ivFile.Read(csp.IV, 0, csp.IV.Length);
break;
}
return csp;
}
private void openInputFile()
{
var ofd = new OpenFileDialog();
ofd.Title = "Eingabedatei?";
if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
this.inFile = ofd.OpenFile();
}
}
private void openIvFile()
{
var ofd = new OpenFileDialog();
ofd.Title = "Initialisierungs Vektor Datei?";
if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
this.ivFile = ofd.OpenFile();
}
}
private void openOutputFile()
{
var sfd = new SaveFileDialog();
sfd.Title = "Ausgabedatei?";
if (sfd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
this.outFile = sfd.OpenFile();
}
}
private void openKeyFile()
{
var ofd = new OpenFileDialog();
ofd.Title = "Schlüsseldatei?";
if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
{
this.keyfile = ofd.OpenFile();
}
}
private void cleanup()
{
foreach (var item in new System.IO.Stream[] { inFile, outFile, keyfile, ivFile })
{
if (item != null)
item.Dispose();
}
ivFile = inFile = outFile = keyfile = null;
}
#region designer kram
/// <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.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(99, 134);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(86, 23);
this.button1.TabIndex = 0;
this.button1.Text = "entschlüsseln";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(99, 105);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(86, 23);
this.button2.TabIndex = 1;
this.button2.Text = "verschlüsseln";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(62, 47);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(34, 13);
this.label1.TabIndex = 2;
this.label1.Text = "Mode";
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(102, 44);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 3;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(284, 262);
this.Controls.Add(this.comboBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "3DES";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox comboBox1;
#endregion
}
}
Daaaaaanke...*soifz*
(nicht getestet... keine garantien... blah)
Code:using System; using System.Linq; using System.Windows.Forms; namespace TrippleDesPlayground { public class Form1 : Form { private System.IO.Stream keyfile, inFile, outFile, ivFile; public Form1() { InitializeComponent(); comboBox1.Items.AddRange(Enum.GetValues(typeof(System.Security.Cryptography.CipherMode)).Cast<object>().ToArray()); comboBox1.SelectedItem = System.Security.Cryptography.CipherMode.ECB; } private void button2_Click(object sender, EventArgs e) { try { openKeyFile(); openInputFile(); openOutputFile(); if (inFile != null && outFile != null && keyfile != null) encrypt(); } finally { cleanup(); } } private void button1_Click(object sender, EventArgs e) { try { openKeyFile(); openInputFile(); openOutputFile(); if (inFile != null && outFile != null && keyfile != null) decrypt(); } finally { cleanup(); } } private void encrypt() { var csp = PrepCsp(); var cs = new System.Security.Cryptography.CryptoStream(outFile, csp.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write); doCrypto(cs); } private void decrypt() { var csp = PrepCsp(); var cs = new System.Security.Cryptography.CryptoStream(outFile, csp.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Write); doCrypto(cs); } private void doCrypto(System.Security.Cryptography.CryptoStream cs) { inFile.CopyTo(cs); cs.FlushFinalBlock(); } private System.Security.Cryptography.TripleDESCryptoServiceProvider PrepCsp() { var csp = new System.Security.Cryptography.TripleDESCryptoServiceProvider(); var key = new Byte[Math.Min((int)csp.KeySize / 8, (int)keyfile.Length)]; keyfile.Read(key, 0, key.Length); csp.Key = key; csp.Mode = (System.Security.Cryptography.CipherMode)comboBox1.SelectedItem; switch (csp.Mode) { case System.Security.Cryptography.CipherMode.ECB: break; default: openIvFile(); csp.IV = new Byte[Math.Min((int)csp.BlockSize / 8, (int)ivFile.Length)]; ivFile.Read(csp.IV, 0, csp.IV.Length); break; } return csp; } private void openInputFile() { var ofd = new OpenFileDialog(); ofd.Title = "Eingabedatei?"; if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { this.inFile = ofd.OpenFile(); } } private void openIvFile() { var ofd = new OpenFileDialog(); ofd.Title = "Initialisierungs Vektor Datei?"; if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { this.ivFile = ofd.OpenFile(); } } private void openOutputFile() { var sfd = new SaveFileDialog(); sfd.Title = "Ausgabedatei?"; if (sfd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { this.outFile = sfd.OpenFile(); } } private void openKeyFile() { var ofd = new OpenFileDialog(); ofd.Title = "Schlüsseldatei?"; if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { this.keyfile = ofd.OpenFile(); } } private void cleanup() { foreach (var item in new System.IO.Stream[] { inFile, outFile, keyfile, ivFile }) { if (item != null) item.Dispose(); } ivFile = inFile = outFile = keyfile = null; } #region designer kram /// <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.button1 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button(); this.label1 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(99, 134); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(86, 23); this.button1.TabIndex = 0; this.button1.Text = "entschlüsseln"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // this.button2.Location = new System.Drawing.Point(99, 105); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(86, 23); this.button2.TabIndex = 1; this.button2.Text = "verschlüsseln"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(62, 47); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(34, 13); this.label1.TabIndex = 2; this.label1.Text = "Mode"; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(102, 44); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(121, 21); this.comboBox1.TabIndex = 3; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 262); this.Controls.Add(this.comboBox1); this.Controls.Add(this.label1); this.Controls.Add(this.button2); this.Controls.Add(this.button1); this.Name = "Form1"; this.Text = "3DES"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Label label1; private System.Windows.Forms.ComboBox comboBox1; #endregion } }
We use essential cookies to make this site work, and optional cookies to enhance your experience.