EaseFilter Demo Project
CreateShareEncryptedFileForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2012 EaseFilter Technologies Inc.
4 // All Rights Reserved
5 //
6 // This software is part of a licensed software product and may
7 // only be used or copied in accordance with the terms of that license.
8 //
10 
11 using System;
12 using System.Collections.Generic;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Drawing;
16 using System.Linq;
17 using System.Text;
18 using System.Windows.Forms;
19 
21 
22 namespace FileProtector
23 {
24  public partial class ShareEncryptedFileCreationForm : Form
25  {
27  {
28  InitializeComponent();
29  textBox_FileAccessFlags.Text = FilterAPI.ALLOW_MAX_RIGHT_ACCESS.ToString();
30  dateTimePicker_ExpireTime.Value = DateTime.Now + TimeSpan.FromDays(1);
31  }
32 
33  private void button_FileAccessFlags_Click(object sender, EventArgs e)
34  {
35  OptionForm optionForm = new OptionForm(OptionForm.OptionType.Access_Flag, textBox_FileAccessFlags.Text);
36 
37  if (optionForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
38  {
39  textBox_FileAccessFlags.Text = optionForm.AccessFlags.ToString();
40  }
41  }
42 
43 
44  private void button_CreateShareEncryptedFile_Click(object sender, EventArgs e)
45  {
46  if (textBox_FileName.Text.Trim().Length == 0)
47  {
48  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
49  MessageBox.Show("The file name can't be empty.", "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error);
50  return;
51  }
52 
53  if (textBox_PassPhrase.Text.Trim().Length == 0)
54  {
55  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
56  MessageBox.Show("The pass phrase can't be empty.", "Create share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error);
57  return;
58  }
59 
60  AESAccessPolicy policy = new AESAccessPolicy();
61 
62  if (textBox_IncludeProcessNames.Text.Trim().Length > 0 || textBox_ExcludeProcessNames.Text.Trim().Length > 0)
63  {
64  policy.AESFlags |= (uint)AESFlags.Flags_Enabled_Check_ProcessName;
65  }
66 
67  if (textBox_IncludeUserNames.Text.Trim().Length > 0 || textBox_ExcludeUserNames.Text.Trim().Length > 0)
68  {
69  policy.AESFlags |= (uint)AESFlags.Flags_Enabled_Check_UserName;
70  }
71 
72  policy.AESFlags |= (uint)AESFlags.Flags_Enabled_Check_AccessFlags | (uint)AESFlags.Flags_Enabled_Expire_Time;
73 
74  string encryptionPassPhrase = textBox_PassPhrase.Text;
75  uint accessFlags = uint.Parse(textBox_FileAccessFlags.Text);
76 
77  policy.AccessFlags = accessFlags;
78  policy.IncludeProcessNames = textBox_IncludeProcessNames.Text.Trim();
79  policy.LengthOfIncludeProcessNames = (uint)textBox_IncludeProcessNames.Text.Length * 2;
80  policy.ExcludeProcessNames = textBox_ExcludeProcessNames.Text.Trim();
81  policy.LengthOfExcludeProcessNames = (uint)textBox_ExcludeProcessNames.Text.Length * 2;
82  policy.IncludeUserNames = textBox_IncludeUserNames.Text.Trim();
83  policy.LengthOfIncludeUserNames = (uint)textBox_IncludeUserNames.Text.Length * 2;
84  policy.ExcludeUserNames = textBox_ExcludeUserNames.Text.Trim();
85  policy.LengthOfExcludeUserNames = (uint)textBox_ExcludeUserNames.Text.Length * 2;
86  policy.ExpireTime = dateTimePicker_ExpireTime.Value.ToUniversalTime().ToFileTimeUtc();
87 
88  string lastError = string.Empty;
89 
90  if (!EncryptionHandler.EncryptFileWithEmbeddedPolicy(textBox_FileName.Text, textBox_PassPhrase.Text, policy, out lastError))
91  {
92  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
93  MessageBox.Show("Create share encrypted file failed with error:" + lastError, "Process share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Error);
94 
95  return;
96  }
97  else
98  {
99  MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
100  MessageBox.Show("Create share encrypted file succeeded.", "Process share encrypted file", MessageBoxButtons.OK, MessageBoxIcon.Information);
101  }
102 
103  }
104 
105 
106  private void checkBox_DisplayPassword_CheckedChanged(object sender, EventArgs e)
107  {
108  if (checkBox_DisplayPassword.Checked)
109  {
110  textBox_PassPhrase.UseSystemPasswordChar = false;
111  }
112  else
113  {
114  textBox_PassPhrase.UseSystemPasswordChar = true;
115  }
116  }
117 
118  private void button_OpenFile_Click(object sender, EventArgs e)
119  {
120  OpenFileDialog openFileDialog = new OpenFileDialog();
121 
122  if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
123  {
124  textBox_FileName.Text = openFileDialog.FileName;
125  }
126  }
127 
128 
129 
130 
131  }
132 }
static bool EncryptFileWithEmbeddedPolicy(string fileName, string passPhrase, AESAccessPolicy policy, out string lastError)
Create an encrypted file with embedded access control policy, distribute the encrypted file via inter...

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com