Click here to Skip to main content
15,898,035 members
Home / Discussions / C#
   

C#

 
GeneralRe: I need to Create a Quiz Program. Pin
Pete O'Hanlon23-Jan-08 11:15
mvePete O'Hanlon23-Jan-08 11:15 
Generaldll reference Pin
Peterson Luiz23-Jan-08 7:27
Peterson Luiz23-Jan-08 7:27 
GeneralRe: dll reference Pin
engsrini23-Jan-08 8:24
engsrini23-Jan-08 8:24 
GeneralRe: dll reference Pin
Peterson Luiz24-Jan-08 8:17
Peterson Luiz24-Jan-08 8:17 
GeneralRe: dll reference Pin
Gareth H23-Jan-08 8:29
Gareth H23-Jan-08 8:29 
GeneralRe: dll reference Pin
Peterson Luiz24-Jan-08 8:20
Peterson Luiz24-Jan-08 8:20 
GeneralRe: dll reference Pin
Brad Grace24-Jan-08 15:51
Brad Grace24-Jan-08 15:51 
QuestionEncrypting a stream Pin
Schokoolero23-Jan-08 7:18
Schokoolero23-Jan-08 7:18 
I'm currently writing a little password-manager to store my passwords and the associated data my way.
Of course I would prefer the stored data not to be plainly readable to anyone, so I thought of encrypting it.

However, I couldn't really find any way of doing it elegantly.

1. I want to enter a password of my choice to encrypt it. Rijndael and others always need a key of a specific length, so the choice of passwords is limited to the accepted length Frown | :( .

2. Some methods I found need an input file and an output file. This is not particularly elegant, since one has to erase the input file (encryption) or the output file (decryption) afterwards, in order not to have a plainly readable version. Other methods encrypt a string, while I am serializing objects in a stream.

Here is what I have so far (without encryption):

Saving:
<br />
private void SaveFile(string path) {<br />
    Stream stream = null;<br />
    try {<br />
        stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None);<br />
<br />
        MemoryStream memoryStream = new MemoryStream();<br />
        GZipStream compressedStream = new GZipStream(stream, CompressionMode.Compress);<br />
        IFormatter formatter = new BinaryFormatter();<br />
        formatter.Serialize(memoryStream, ((PasswordList)ActiveMdiChild).List);<br />
        memoryStream.WriteTo(compressedStream);<br />
<br />
        compressedStream.Flush();<br />
        compressedStream.Close();<br />
    } catch (Exception r) {<br />
         throw new ApplicationException("File could not be created " + r);<br />
    } finally { if (null != stream) stream.Close(); }<br />
}<br />


Opening:
<br />
private void openToolStripMenuItem_Click(object sender, EventArgs e) {<br />
    OpenFileDialog openFile = new OpenFileDialog();<br />
    openFile.Title = "Open";<br />
    openFile.InitialDirectory = Environment.CurrentDirectory;<br />
<br />
    if (openFile.ShowDialog() == DialogResult.OK) {<br />
        Stream stream = null;<br />
        try {<br />
            IFormatter formatter = new BinaryFormatter();<br />
            stream = new FileStream(openFile.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);<br />
            GZipStream compressedStream = new GZipStream(stream, CompressionMode.Decompress);<br />
            PasswordList newList = new PasswordList(this, (List<entry>)formatter.Deserialize(compressedStream));<br />
            compressedStream.Close();<br />
<br />
            newList.MdiParent = this;<br />
            newList.filename = openFile.FileName;<br />
            InitializeNewList(newList);<br />
        } catch (Exception r) {<br />
            throw new ApplicationException("File could not be opened" + r, r);<br />
        } finally { if (null != stream) stream.Close(); }<br />
    }<br />
}<br />
</entry>


Does anyone know an elegant way (not writing the file, encrypting it and then throwing away the original file) to include encryption and decryption with an arbitrary password (that I will get through a dialog) in that code.
GeneralRe: Encrypting a stream Pin
Giorgi Dalakishvili23-Jan-08 7:51
mentorGiorgi Dalakishvili23-Jan-08 7:51 
GeneralRe: Encrypting a stream Pin
Schokoolero23-Jan-08 8:17
Schokoolero23-Jan-08 8:17 
GeneralRe: Encrypting a stream Pin
DaveyM6923-Jan-08 9:14
professionalDaveyM6923-Jan-08 9:14 
GeneralRe: Encrypting a stream Pin
Skippums23-Jan-08 10:35
Skippums23-Jan-08 10:35 
QuestionExtending Hashtable - is there a better way? [modified] Pin
Clive D. Pottinger23-Jan-08 6:59
Clive D. Pottinger23-Jan-08 6:59 
GeneralRe: Extending Hashtable - is there a better way? Pin
engsrini23-Jan-08 8:43
engsrini23-Jan-08 8:43 
GeneralCreating a WPF app with notpad and command-line compiler. Pin
CataclysmicQuantum23-Jan-08 6:29
CataclysmicQuantum23-Jan-08 6:29 
GeneralRe: Creating a WPF app with notpad and command-line compiler. Pin
led mike23-Jan-08 6:54
led mike23-Jan-08 6:54 
GeneralRe: Creating a WPF app with notpad and command-line compiler. Pin
CataclysmicQuantum23-Jan-08 7:03
CataclysmicQuantum23-Jan-08 7:03 
GeneralRe: Creating a WPF app with notpad and command-line compiler. Pin
led mike23-Jan-08 7:19
led mike23-Jan-08 7:19 
GeneralRe: Creating a WPF app with notpad and command-line compiler. Pin
CataclysmicQuantum23-Jan-08 7:37
CataclysmicQuantum23-Jan-08 7:37 
GeneralRe: Creating a WPF app with notpad and command-line compiler. Pin
NormDroid25-Jan-08 10:05
professionalNormDroid25-Jan-08 10:05 
GeneralName of DLL [SOLVED] Pin
#realJSOP23-Jan-08 5:24
professional#realJSOP23-Jan-08 5:24 
GeneralRe: Name of DLL [SOLVED] Pin
Justin Perez23-Jan-08 5:37
Justin Perez23-Jan-08 5:37 
QuestionGenerics [modified] Pin
ArneKruger23-Jan-08 4:06
ArneKruger23-Jan-08 4:06 
GeneralRe: Generics Pin
Alan Balkany23-Jan-08 4:18
Alan Balkany23-Jan-08 4:18 
GeneralRe: Generics [modified] Pin
ArneKruger23-Jan-08 4:31
ArneKruger23-Jan-08 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.