source: trunk/CrypPlugins/AES/AESSettings.cs @ 2220

Last change on this file since 2220 was 1259, checked in by Matthäus Wander, 12 years ago

shortened license text to boilerplate notice in all source files

File size: 7.3 KB
Line 
1/*
2   Copyright 2008 Dr. Arno Wacker, University of Duisburg-Essen
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using System.IO;
22using Cryptool.PluginBase;
23using System.Security.Cryptography;
24using System.ComponentModel;
25using Cryptool.PluginBase.Miscellaneous;
26
27namespace Cryptool.Plugins.Cryptography.Encryption
28{
29    public class AESSettings : ISettings
30    {
31        private bool hasChanges = false;
32        private int action = 0; //0=encrypt, 1=decrypt
33        private int cryptoAlgorithm = 0; // 0=AES, 1=Rijndael
34        private int blocksize = 0; // 0=128, 1=192, 2=256
35        private int keysize = 0; // 0=128, 1=192, 2=256
36        private int mode = 0; //0="ECB", 1="CBC", 2="CFB", 3="OFB"
37        private int padding = 0; ////0="Zeros"=default, 1="None", 2="PKCS7" , 3="ANSIX923", 4="ISO10126"
38
39        [ContextMenu("Cryptographic algorithm", "Select which symmetric cipher you want to use", 1, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, "Advanced Encryption Standard (AES)", "Rijndael")]
40        [TaskPane("Cryptographic algorithm", "Select which symmetric cipher you want to use", "", 0, false, DisplayLevel.Experienced, ControlType.ComboBox, new string[] { "Advanced Encryption Standard (AES)", "Rijndael" })]
41        public int CryptoAlgorithm
42        {
43            get { return this.cryptoAlgorithm; }
44            set
45            {
46                if (((int)value) != cryptoAlgorithm) hasChanges = true;
47                this.cryptoAlgorithm = (int)value;
48                if (cryptoAlgorithm == 0)
49                {
50                    blocksize = 0;
51                    OnPropertyChanged("Blocksize");
52                }
53                OnPropertyChanged("CryptoAlgorithm");
54
55                switch (cryptoAlgorithm)
56                {
57                  case 0:
58                    ChangePluginIcon(0);
59                    break;
60                  case 1:
61                    ChangePluginIcon(3);
62                    break;
63                  default:
64                    break;
65                }
66            }
67        }
68
69        [ContextMenu("Action", "Do you want the input data to be encrypted or decrypted?", 2, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, new int[] { 1, 2 }, "Encrypt", "Decrypt")]
70        [TaskPane("Action", "Do you want the input data to be encrypted or decrypted?", "", 2, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "Encrypt", "Decrypt" })]
71        public int Action
72        {
73            get { return this.action; }
74            set 
75            { 
76              if (((int)value) != action) hasChanges = true;
77              this.action = (int)value;
78              OnPropertyChanged("Action");             
79            }
80        }
81
82
83        [ContextMenu("Keysize", "Select the key size. Note that providing a longer key will result in cutting the overlapping bytes, providing a shorter key will result in filling up with zeroes.", 3, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, "128 Bits", "192 Bits", "256 Bits")]
84        [TaskPane("Keysize", "Select the key size. Note that providing a longer key will result in cutting the overlapping bytes, providing a shorter key will result in filling up with zeroes.", "", 3, false, DisplayLevel.Beginner, ControlType.ComboBox, new String[] { "128 Bits", "192 Bits", "256 Bits" })]
85        public int Keysize
86        {
87            get { return this.keysize; }
88            set
89            {
90                if (((int)value) != keysize) hasChanges = true;
91                this.keysize = (int)value;
92                OnPropertyChanged("Keysize");
93            }
94        }
95
96
97        [ContextMenu("Blocksize", "Select the block size (applies only to Rijndael)", 4, DisplayLevel.Experienced, ContextMenuControlType.ComboBox, null, "128 Bits", "192 Bits", "256 Bits")]
98        [TaskPane("Blocksize", "Select the block size (applies only to Rijndael)", "", 4, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "128 Bits", "192 Bits", "256 Bits" })]
99        public int Blocksize
100        {
101            get { return this.blocksize; }
102            set
103            {
104                if (((int)value) != blocksize) hasChanges = true;
105                this.blocksize = (int)value;
106                if (blocksize > 0)
107                {
108                    cryptoAlgorithm = 1;
109                    OnPropertyChanged("CryptoAlgorithm");
110                }
111                OnPropertyChanged("Blocksize");
112            }
113        }
114
115        [ContextMenu("Chaining mode", "Select the block cipher mode of operation.", 5, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, new String[] { "Electronic Code Book (ECB)", "Cipher Block Chaining (CBC)", "Cipher Feedback (CFB)" })]
116        [TaskPane("Chaining mode", "Select the block cipher mode of operation.", "", 5, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "Electronic Code Book (ECB)", "Cipher Block Chaining (CBC)", "Cipher Feedback (CFB)" })]
117        public int Mode
118        {
119            get { return this.mode; }
120            set 
121            {
122              if (((int)value) != mode) hasChanges = true;
123              this.mode = (int)value;
124              OnPropertyChanged("Mode");
125            }
126        }
127
128        [ContextMenu("Padding mode", "Select a mode to fill partial data blocks.", 6, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, "Zeros", "None", "PKCS7", "ANSIX923", "ISO10126")]
129        [TaskPane("Padding mode", "Select a mode to fill partial data blocks.", "", 6, false, DisplayLevel.Experienced, ControlType.ComboBox, new String[] { "Zeros", "None", "PKCS7", "ANSIX923", "ISO10126" })]
130        public int Padding
131        {
132            get { return this.padding; }
133            set 
134            {
135              if (((int)value) != padding) hasChanges = true;
136              this.padding = (int)value;
137              OnPropertyChanged("Padding");
138            }
139        }
140
141        public bool HasChanges
142        {
143          get { return hasChanges; }
144          set { hasChanges = value; }
145        }
146
147        #region INotifyPropertyChanged Members
148
149        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
150
151        protected void OnPropertyChanged(string name)
152        {
153          EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
154        }
155
156        #endregion
157
158        public event StatusChangedEventHandler OnPluginStatusChanged;
159
160        private void ChangePluginIcon(int Icon)
161        {
162          if (OnPluginStatusChanged != null) OnPluginStatusChanged(null, new StatusEventArgs(StatusChangedMode.ImageUpdate, Icon));
163        }
164    }
165}
Note: See TracBrowser for help on using the repository browser.