Autor Beitrag
maxx
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70



BeitragVerfasst: Fr 12.02.10 20:55 
hello,

mal wieder eine Frage. Habe folgendes Programm:

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
using System;
using System.Text; // Encoding
using System.Windows.Forms;
using System.Security.Cryptography; 
// Rfc2898DeriveBytes, RijndaelManaged, ICryptoTransform, CryptoStream, CryptoStreamMode
using System.IO; // FileStream, File, FileMode, StreamWriter
namespace WindowsFormsApplication1
{
   public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
         // Ausgangsmaterial zum Erzeugen eines Keys
         string sPlain = "ö";  // ist ev. wem bekannt
         string sSalt = "12345678"// muss absolut geheim bleiben (mind. 8 Zeichen)

         // Key und IV erzeugen:
         byte[] aSalt=Encoding.ASCII.GetBytes(sSalt);
         Rfc2898DeriveBytes oEnc = new Rfc2898DeriveBytes(sPlain, aSalt);

         // Verschlüsselungsalgorithmus:
         RijndaelManaged oAlg = new RijndaelManaged();
         oAlg.Key = oEnc.GetBytes(oAlg.KeySize   / 8); // immer 32 Bytes
         oAlg.IV  = oEnc.GetBytes(oAlg.BlockSize / 8); // immer 16 Bytes
         // Key und IV sind 2 unterschiedliche Sachen.
         // Sie sind jedoch bei jedem Programmaufruf gleich 
         // (sofern man sPlain und sSalt nicht ändert).

         ICryptoTransform ict = oAlg.CreateEncryptor(); // mit aktuellem Key und IV

         // in Datei schreiben:
         FileStream fs = File.Open(@"C:\xxx.txt", FileMode.OpenOrCreate);
         CryptoStream cs = new CryptoStream
         (  
            fs,
            ict,
            CryptoStreamMode.Write
         );
         StreamWriter sw = new StreamWriter(cs);
         sw.WriteLine(sPlain);

         sw.Close();
         cs.Close();
         fs.Close();
      }
   }
}

Es wird eine Datei angelegt, der Inhalt ist unleserlich. Soweit alles OK. Allerdings frage ich mich, wie ich IV richtig einbauen muss, damit der Text in der Datei bei jedem Aufruf anders ausschaut.?.?.?.?.?.?


Moderiert von user profile iconKha: Topic aus C# - Die Sprache verschoben am Fr 12.02.2010 um 22:30
maxx Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 70



BeitragVerfasst: Do 18.02.10 13:33 
Das war ein Misverständnis. Ich hatte die Theorie falsch verstanden. Soll ja nie anders aussehen. Sorry.