Click here to Skip to main content
Click here to Skip to main content

Password file manager - simple double click to look at your password file

, 30 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Password file manager - simple double click to look at your password file.

Sample Image - CryptoViewer.jpg

Introduction

I have too many passwords to remember. Not to mention all the credit card numbers, bank accounts, URLs, VPN settings... the list goes on.

I've had the need, for a long time, for an encrypted file that I could double click on and simply be prompted for a password to look at the file, make changes, copy a word or two, and close it. The closest I got was PGP, which I had to decrypt the file to disk, look at it, wipe it, or edit it, re-encrypt it, then wipe it. I JUST WANTED ONE WORD!!!

Points of Interest

So I dragged a RichTextBox to my new project, added some menu items, and whalla! A simple UI to start. Two methods were needed, Encrypt() and Decrypt(), the rest was just wired up code - nothing exciting.

I used DES which uses a key and an IV. Both are 8 bytes long. To make the key and IV, I use the password in a simple algorithm:

private string Password
{
    set
    {
        IV = value;
        while ( IV.Length < 8 ) IV += value;
        IV = IV.Substring(0,8);

        ArrayList a = new ArrayList();

        foreach ( char c in value.ToCharArray() )
        {
            a.Add(c);
        }

        a.Reverse();
        string output = new string((char[])a.ToArray(typeof(char)));

        KEY = output;
        while ( KEY.Length < 8 ) KEY += output;
        KEY = KEY.Substring(0,8);
    }
}

Admittedly this is not the best way, and I will update it when I get a chance. Most the code is wired up and file reads/writes, but the Encrypt() and Decrypt() methods are shown below:

public static byte[] Encrypt(byte[] data, byte[] key, byte[] IV)
{
    MemoryStream writer = new MemoryStream();
    writer.SetLength(0);

    DESCryptoServiceProvider crypto = new DESCryptoServiceProvider();
    crypto.Padding = System.Security.Cryptography.PaddingMode.PKCS7;

    CryptoStream encStream = new CryptoStream(writer, 
       crypto.CreateEncryptor(key, IV), CryptoStreamMode.Write);

    encStream.Write(data,0, data.Length);
    encStream.FlushFinalBlock();

    byte[] b = new byte[writer.Length];
    writer.Position = 0;
    writer.Read( b, 0, (int)writer.Length );

    encStream.Close();
    writer.Close();

    return b;
}

public static Stream Decrypt(byte[] data, byte[] key, byte[] IV)
{
    MemoryStream writer = new MemoryStream();
    writer.SetLength(0);

    DESCryptoServiceProvider crypto = new DESCryptoServiceProvider();
    crypto.Padding = System.Security.Cryptography.PaddingMode.PKCS7;

    CryptoStream encStream = new CryptoStream(writer, 
      crypto.CreateDecryptor(key, IV), CryptoStreamMode.Write);

    encStream.Write(data,0, data.Length);
    encStream.FlushFinalBlock();

    writer.Position = 0;             
    return writer;
}

Notice the use of the PaddingMode. You may run into a lot of problems without it, including data loss. Also the keys need to be exactly the right size - 8 bytes long. I passed back the stream to make my code simpler, and I was planning to do it with the Encrypt() algorithm later.

Using the code

The demo is really all you need. Create a file association to your liking, so that you can double click on it to be prompted for a password to open it.

Here are the steps:

  1. Right hand click on the Desktop -> New -> Text Document.
  2. Rename the document to anything, with the file extension you want to use (i.e. file.cpt)
  3. Right hand click on the file -> Open With -> Choose program.
  4. Browse for CryptoViewer and click OK.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Dan Glass
Architect support.com
Australia Australia

Comments and Discussions

 
GeneralPassword Stopped Working PinmemberHollerith22-Jan-10 10:45 
NewsTwo other related encryption articles in CodeProject ... PinmemberTony Selke27-Sep-07 8:05 
GeneralMust have NET software installed Pinmemberartstar23-Apr-06 12:49 
GeneralRe: Must have NET software installed PinmemberJason Barry26-Aug-08 10:18 
Generalescape characters Pinmembertalljames110-Oct-04 17:45 
GeneralDeja-vu PinmemberSteven Campbell13-Apr-04 8:24 
GeneralKey Length Question... Pinmembermikasa27-Jun-03 10:12 
GeneralRe: Key Length Question... PinmemberDan Glass12-Jul-03 21:19 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 31 Mar 2003
Article Copyright 2003 by Dan Glass
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid