<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[verschlüsselung]]></title><description><![CDATA[<p>hey, hab problem mit der verschlüsselung von daten.</p>
<p>Habn Programm wo ich von einer Liste daten aufm pc speichere.<br />
diese daten sollen jetzt verschlüsselgespeichert werden.</p>
<p>Hab es versucht mit BinaryWriter auf *.bin datei zu speichern aber das alleine reicht nicht und ziet die wörter nur mit leerzeichen außeinander.</p>
<p>Hab ne methode gefunden im internet um di daten i zeichen umzuwandeln,bzw ist di liste dann in einer ganzen reihe.</p>
<p>Code:</p>
<pre><code class="language-csharp">using System.Collections.Generic;
using Microsoft.Win32;
using System.Text;
using System;
using System.IO;
using System.Security.Cryptography;

namespace Dreiecksbeispiel_v1
{
    class BinaryReadWrite
    {
        private readonly byte[] key = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
        private readonly byte[] iv = new byte[] { 65, 110, 68, 26, 69, 178, 200, 219 };

        public void write(List&lt;User&gt; userList)
        {

            MemoryStream ms = new MemoryStream();

            CryptoStream cryptoStream = new CryptoStream(ms,
                                                         new TripleDESCryptoServiceProvider().CreateEncryptor(key, iv),
                                                         CryptoStreamMode.Write);
            for (int i = 0; i &lt; userList.Count; i++)
            {
                byte[] toEncrypt = ASCIIEncoding.ASCII.GetBytes(userList[i].GetUserName() + &quot;|&quot; + userList[i].GetPassword() + &quot;|&quot;
                             + userList[i].GetIsAdmin() + &quot;\n&quot;);
                cryptoStream.Write(toEncrypt, 0, toEncrypt.Length);
            }
            cryptoStream.FlushFinalBlock();

            byte[] ret = ms.ToArray();

            FileStream fs = File.Create(&quot;User.bin&quot;);
            UTF8Encoding utf8 = new UTF8Encoding();
            BinaryWriter bw = new BinaryWriter(fs,utf8);

            bw.Write(ret);

            bw.Close();
            cryptoStream.Close();
            ms.Close();
        }

        public void read()
        {
            FileStream readStream = new FileStream(&quot;User.bin&quot;, FileMode.Open);
            BinaryReader br = new BinaryReader(readStream);
            byte[] data = null;

            for (int i = 0; i &lt; br.BaseStream.Length; i++)
            {
                data = br.ReadBytes(i);
            }

            readStream.Close();
            br.Close();

            MemoryStream memoryStream = new MemoryStream(data);

            CryptoStream cryptoStream = new CryptoStream(memoryStream,new TripleDESCryptoServiceProvider().CreateDecryptor(this.key,this.iv),CryptoStreamMode.Read);
            byte[] fromEncrypt = new byte[data.Length];
            cryptoStream.Read(fromEncrypt, 0, fromEncrypt.Length);

            Console.WriteLine(ASCIIEncoding.ASCII.GetString(fromEncrypt));
        }

    }
}
</code></pre>
<p>Das write funktioniert eig gut.<br />
Nur beim read geht gar nichts.</p>
<p>wie kann ich das read so baun das ich wieder alles normal habe und dann noch wieder jeweils in liste speichere?</p>
<p>Edit by Moderator Dravere: [cs]-Tags reingetan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/307023/verschlüsselung</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 12:12:02 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/307023.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 14 Aug 2012 12:09:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to verschlüsselung on Tue, 14 Aug 2012 17:15:26 GMT]]></title><description><![CDATA[<p>hey, hab problem mit der verschlüsselung von daten.</p>
<p>Habn Programm wo ich von einer Liste daten aufm pc speichere.<br />
diese daten sollen jetzt verschlüsselgespeichert werden.</p>
<p>Hab es versucht mit BinaryWriter auf *.bin datei zu speichern aber das alleine reicht nicht und ziet die wörter nur mit leerzeichen außeinander.</p>
<p>Hab ne methode gefunden im internet um di daten i zeichen umzuwandeln,bzw ist di liste dann in einer ganzen reihe.</p>
<p>Code:</p>
<pre><code class="language-csharp">using System.Collections.Generic;
using Microsoft.Win32;
using System.Text;
using System;
using System.IO;
using System.Security.Cryptography;

namespace Dreiecksbeispiel_v1
{
    class BinaryReadWrite
    {
        private readonly byte[] key = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
        private readonly byte[] iv = new byte[] { 65, 110, 68, 26, 69, 178, 200, 219 };

        public void write(List&lt;User&gt; userList)
        {

            MemoryStream ms = new MemoryStream();

            CryptoStream cryptoStream = new CryptoStream(ms,
                                                         new TripleDESCryptoServiceProvider().CreateEncryptor(key, iv),
                                                         CryptoStreamMode.Write);
            for (int i = 0; i &lt; userList.Count; i++)
            {
                byte[] toEncrypt = ASCIIEncoding.ASCII.GetBytes(userList[i].GetUserName() + &quot;|&quot; + userList[i].GetPassword() + &quot;|&quot;
                             + userList[i].GetIsAdmin() + &quot;\n&quot;);
                cryptoStream.Write(toEncrypt, 0, toEncrypt.Length);
            }
            cryptoStream.FlushFinalBlock();

            byte[] ret = ms.ToArray();

            FileStream fs = File.Create(&quot;User.bin&quot;);
            UTF8Encoding utf8 = new UTF8Encoding();
            BinaryWriter bw = new BinaryWriter(fs,utf8);

            bw.Write(ret);

            bw.Close();
            cryptoStream.Close();
            ms.Close();
        }

        public void read()
        {
            FileStream readStream = new FileStream(&quot;User.bin&quot;, FileMode.Open);
            BinaryReader br = new BinaryReader(readStream);
            byte[] data = null;

            for (int i = 0; i &lt; br.BaseStream.Length; i++)
            {
                data = br.ReadBytes(i);
            }

            readStream.Close();
            br.Close();

            MemoryStream memoryStream = new MemoryStream(data);

            CryptoStream cryptoStream = new CryptoStream(memoryStream,new TripleDESCryptoServiceProvider().CreateDecryptor(this.key,this.iv),CryptoStreamMode.Read);
            byte[] fromEncrypt = new byte[data.Length];
            cryptoStream.Read(fromEncrypt, 0, fromEncrypt.Length);

            Console.WriteLine(ASCIIEncoding.ASCII.GetString(fromEncrypt));
        }

    }
}
</code></pre>
<p>Das write funktioniert eig gut.<br />
Nur beim read geht gar nichts.</p>
<p>wie kann ich das read so baun das ich wieder alles normal habe und dann noch wieder jeweils in liste speichere?</p>
<p>Edit by Moderator Dravere: [cs]-Tags reingetan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2241788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2241788</guid><dc:creator><![CDATA[slei1337]]></dc:creator><pubDate>Tue, 14 Aug 2012 17:15:26 GMT</pubDate></item><item><title><![CDATA[Reply to verschlüsselung on Tue, 14 Aug 2012 16:22:04 GMT]]></title><description><![CDATA[<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>slei1337 schrieb:</p>
<blockquote>
<p>Das write funktioniert eig gut.<br />
Nur beim read geht gar nichts.</p>
</blockquote>
<p>Debuggen! Laß dir beim Schreiben mal die einzelnen Zwischenschritte (Byte-Array) ausgeben und vergleiche diese dann beim Einlesen...</p>
<p>P.S. Anstatt ASCIIEncoding.ASCII würde ich besser gleich ASCIIEncoding.Default oder ASCIIEncoding.ASCII.Utf8 benutzen (da sonst Umlaute etc. als Fragezeichen '?' ausgegeben werden).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2241868</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2241868</guid><dc:creator><![CDATA[Th69]]></dc:creator><pubDate>Tue, 14 Aug 2012 16:22:04 GMT</pubDate></item></channel></rss>