Changeset 419 for trunk/CrypPlugins/AES


Ignore:
Timestamp:
Aug 7, 2009, 12:08:23 AM (12 years ago)
Author:
Thomas Schmid
Message:
  • merged IControl branch to trunk
  • added KeySearcher sample: KeySearcher-Sample
  • changed some plugins to work with new enumeration
  • new bins
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:mergeinfo set to
      /branches/IControl_Test_Branch393-418
  • trunk/CrypPlugins/AES/AES.cs

    r302 r419  
    216216using Cryptool.PluginBase.Miscellaneous;
    217217using System.Runtime.Remoting.Contexts;
     218using Cryptool.PluginBase.Control;
    218219
    219220
     
    223224    [Author("Dr. Arno Wacker", "arno.wacker@cryptool.org", "Uni Duisburg", "http://www.uni-duisburg-essen.de")]
    224225    [PluginInfo(false, "AES", "Advanced Encryption Standard (Rijndael)", "AES/DetailedDescription/Description.xaml", "AES/Images/AES.png", "AES/Images/encrypt.png", "AES/Images/decrypt.png", "AES/Images/Rijndael.png")]
    225     [EncryptionType(EncryptionType.SymmetricBlock)]   
     226    [EncryptionType(EncryptionType.SymmetricBlock)]
    226227    public class AES : ContextBoundObject, IEncryption
    227228    {
     
    254255        }
    255256
    256         [PropertyInfo(Direction.Input, "Input", "Data to be encrypted or decrypted", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
     257        [PropertyInfo(Direction.InputData, "Input", "Data to be encrypted or decrypted", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
    257258        public CryptoolStream InputStream
    258259        {
     
    276277        }
    277278
    278         [PropertyInfo(Direction.Input, "Key", "The provided key should be 16, 24 or 32 bytes, dependig on the settings. Too short/long keys will be extended/truncated!", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
     279        [PropertyInfo(Direction.InputData, "Key", "The provided key should be 16, 24 or 32 bytes, dependig on the settings. Too short/long keys will be extended/truncated!", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
    279280        public byte[] InputKey
    280281        {
     
    287288        }
    288289
    289         [PropertyInfo(Direction.Input, "IV", "The initialisation vector (IV) which is used in chaining modes. It always must be the same as the blocksize.", "", true, false, DisplayLevel.Professional, QuickWatchFormat.Hex, null)]
     290        [PropertyInfo(Direction.InputData, "IV", "The initialisation vector (IV) which is used in chaining modes. It always must be the same as the blocksize.", "", true, false, DisplayLevel.Professional, QuickWatchFormat.Hex, null)]
    290291        public byte[] InputIV
    291292        {
     
    298299        }
    299300
    300         [PropertyInfo(Direction.Output, "Output stream", "Encrypted or decrypted output data", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
     301        [PropertyInfo(Direction.OutputData, "Output stream", "Encrypted or decrypted output data", "", true, false, DisplayLevel.Beginner, QuickWatchFormat.Hex, null)]
    301302        public CryptoolStream OutputStream
    302303        {
     
    461462            int bytesRead;
    462463            int position = 0;
    463             GuiLogMessage("Starting encryption [Keysize=" + p_alg.KeySize.ToString() + " Bits, Blocksize=" + p_alg.BlockSize.ToString() + " Bits]", NotificationLevel.Info);
     464            string mode = action == 0 ? "encryption" : "decryption";
     465            GuiLogMessage("Starting " + mode + " [Keysize=" + p_alg.KeySize.ToString() + " Bits, Blocksize=" + p_alg.BlockSize.ToString() + " Bits]", NotificationLevel.Info);
    464466            DateTime startTime = DateTime.Now;
    465467            while ((bytesRead = p_crypto_stream.Read(buffer, 0, buffer.Length)) > 0 && !stop)
     
    476478
    477479            long outbytes = outputStream.Length;
    478             p_crypto_stream.Flush();
     480            p_crypto_stream.Flush();           
    479481            // p_crypto_stream.Close();
    480482            DateTime stopTime = DateTime.Now;
     
    484486            if (!stop)
    485487            {
    486                 GuiLogMessage("Encryption complete! (in: " + inputStream.Length.ToString() + " bytes, out: " + outbytes.ToString() + " bytes)", NotificationLevel.Info);
     488                mode = action == 0 ? "Encryption" : "Decryption";
     489                GuiLogMessage(mode + " complete! (in: " + inputStream.Length.ToString() + " bytes, out: " + outbytes.ToString() + " bytes)", NotificationLevel.Info);
    487490                GuiLogMessage("Wrote data to file: " + outputStream.FileName, NotificationLevel.Info);
    488491                GuiLogMessage("Time used: " + duration.ToString(), NotificationLevel.Debug);
     
    490493                OnPropertyChanged("OutputStream");
    491494            }
    492 
     495            CryptoolStream test = outputStream;
    493496            if (stop)
    494497            {
     
    641644
    642645        #endregion
     646
     647        private IControlEncryption testSlave;
     648        [PropertyInfo(Direction.ControlSlave, "AES Slave", "aösdflkj", "", DisplayLevel.Beginner)]
     649        public IControlEncryption TestSlave
     650        {
     651          get
     652          {
     653            if (testSlave == null)
     654              testSlave = new AESControl(this);
     655            return testSlave;
     656          }
     657        }     
     658    }
     659
     660    public class AESControl : IControlEncryption
     661    {
     662      private AES plugin;
     663      private AES dec;
     664
     665      public AESControl(AES Plugin)
     666      {
     667        this.plugin = Plugin;
     668        dec = (AES)plugin.GetType().CreateObject();
     669      }
     670
     671      #region IControlEncryption Members
     672
     673      public byte[] Encrypt(byte[] key, byte[] data, byte[] iv)
     674      {
     675        ((AESSettings)plugin.Settings).Action = 0;
     676        return execute(key, data, iv);
     677      }
     678
     679      public byte[] Decrypt(byte[] key, byte[] data, byte[] iv)
     680      {
     681        ((AESSettings)plugin.Settings).Action = 1;
     682        return execute(key, data, iv);
     683      }
     684
     685      private byte[] execute(byte[] key, byte[] data, byte[] iv)
     686      {
     687        plugin.InputKey = key;
     688        plugin.InputIV = iv;
     689        CryptoolStream cs = new CryptoolStream();
     690        cs.OpenRead(this.GetType().Name, data);
     691        plugin.InputStream = cs;
     692        plugin.Execute();
     693        CryptoolStream output = plugin.OutputStream;
     694
     695        byte[] byteValues = new byte[output.Length];
     696        int bytesRead;
     697        output.Seek(0, SeekOrigin.Begin);
     698        bytesRead = output.Read(byteValues, 0, byteValues.Length);
     699        plugin.Dispose();
     700        cs.Close();
     701        output.Close();
     702        return byteValues;
     703      }
     704
     705      #endregion
    643706    }
    644707}
Note: See TracChangeset for help on using the changeset viewer.