|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionDo you need to keep some of your files unreadable to others? Do you want to be sure that when you leave your workplace your files are secure? CryptoSafe is a tool that enables you to encrypt your private files so that no one else can read them. Key features of CryptoSafe:
The algorithm - RijndaelManagedWhy RijndaelManaged? As written in part 1: because it is strong, fast, and managed, what ensures to run on every machine with .NET framework installed. The ApplicationThere are very few steps you have to do for using CryptoSafe:
You can refresh file list by clicking "re" button if necessary (when folder contents change). The CodeCreating file list with proper iconsvoid refreshFileList()
{
listView1.Items.Clear();
listView2.Items.Clear();
if (workingDirectory == null || workingDirectory.Length == 0)
return;
this.Cursor = Cursors.WaitCursor;
try
{
string[] files = Directory.GetFiles(workingDirectory);
int imageIndex = 0;
imageList1.Images.Clear();
SHFILEINFO shinfo = new SHFILEINFO();
listView1.BeginUpdate();
listView2.BeginUpdate();
foreach (string s in files)
{
FileInfo fi = new FileInfo(s);
if (fi.Extension.ToLower() == ".enc")
{
ListViewItem lvi = new ListViewItem(fi.Name);
lvi.SubItems.Add(fi.Length.ToString());
lvi.Tag = fi.FullName;
lvi.ImageIndex = 0;
listView2.Items.Add(lvi);
}
else
{
//extract file icon
IntPtr hImgSmall = MyShell.SHGetFileInfo(s, 0,
ref shinfo,(uint)Marshal.SizeOf(shinfo),
MyShell.SHGFI_ICON |
MyShell.SHGFI_SMALLICON);
//The icon is returned in the hIcon member of the shinfo
//struct
System.Drawing.Icon myIcon =
System.Drawing.Icon.FromHandle(shinfo.hIcon);
imageList1.Images.Add(myIcon);
ListViewItem lvi = new ListViewItem(fi.Name);
lvi.ImageIndex = imageIndex++;
lvi.SubItems.Add(fi.Length.ToString());
lvi.Tag = fi.FullName;
listView1.Items.Add(lvi);
}
}
listView1.EndUpdate();
listView2.EndUpdate();
}
catch(IOException ex)
{
MessageBox.Show("refreshFileList IOexception: "+ex.Message);
}
finally
{
this.Cursor = Cursors.Arrow;
}}
Save settings in isolated storagevoid saveSettings()
{
// Retrieve an IsolatedStorageFile
// for the current Domain and Assembly.
try
{
IsolatedStorageFile isoFile =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain , null,null);
IsolatedStorageFileStream fs = new
IsolatedStorageFileStream("cryptoSettings.txt",
FileMode.Create,FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
foreach (string fname in lbFolders.Items)
sw.WriteLine(fname);
sw.Close();
isoFile.Close();
}
catch (IsolatedStorageException ex)
{
MessageBox.Show(ex.Message);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
}
}
Load settings from isolated storagevoid loadSettings()
{
// Retrieve an IsolatedStorageFile for the current Domain and Assembly.
try
{
lbFolders.Items.Clear();
IsolatedStorageFile isoFile =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Assembly |
IsolatedStorageScope.Domain , null,null);
IsolatedStorageFileStream fs = new
IsolatedStorageFileStream("cryptoSettings.txt",
FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs);
while (true)
{
string l = sr.ReadLine();
if (l == null)
break;
lbFolders.Items.Add(l);
}
sr.Close();
isoFile.Close();
}
catch (FileNotFoundException)
{
MessageBox.Show("application settings" +
" file not found - please set working folders");
}
catch (IsolatedStorageException ex)
{
MessageBox.Show(ex.Message);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message);
}
}
File encryptionpublic void EncryptData(String inName,
String outName, byte[] rijnKey, byte[] rijnIV)
{
FileStream fin = null;
FileStream fout = null;
CryptoStream encStream = null;
try
{
//Create the file streams to handle the input and output files.
fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
fout = new FileStream(outName, FileMode.Create, FileAccess.Write);
//fout.SetLength(0);
//Create variables to help with read and write.
//This is intermediate storage for the encryption.
byte[] bin = new byte
File decryptionpublic bool DecryptData(String inName,
String outName, byte[] rijnKey, byte[] rijnIV)
{
//Create the file streams to handle the input and output files.
FileStream fin = null;
FileStream fout = null;
CryptoStream decStream = null;
try
{
fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
//Create variables to help with read and write.
//This is intermediate storage for the encryption.
byte[] bin = new byte
|
|||||||||||||||||||||||||||||||||||||||||||||||