Ignore:
Timestamp:
Jan 15, 2010, 4:19:10 PM (12 years ago)
Author:
arnold
Message:

Changed KeySearcher-IControl-stuff (Ticket 131)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/KeySearcher.cs

    r1069 r1083  
    1313using Cryptool.PluginBase.Miscellaneous;
    1414using System.IO;
     15using Cryptool.PluginBase.IO;
    1516
    1617namespace KeySearcher
     
    4849        private bool stop;
    4950
     51        #region IControlEncryption + IControlCost + InputFields
     52
    5053        #region IControlEncryption Members
    5154
     
    9396        #endregion
    9497
     98        /* BEGIN: following lines are from Arnie - 2010.01.12 */
     99        CryptoolStream decryptedData;
     100        [PropertyInfo(Direction.InputData,"Encrypted Data","Encrypted data out of an Encryption PlugIn","",true,false,DisplayLevel.Beginner,QuickWatchFormat.Hex,"")]
     101        public CryptoolStream DecryptedData
     102        {
     103            get { return this.decryptedData; }
     104            set
     105            {
     106                if (value != this.decryptedData)
     107                {
     108                    this.decryptedData = value;
     109                    cryptoolStreamChanged = true;
     110                    OnPropertyChanged("EncryptedData");
     111                }
     112            }
     113        }
     114
     115        /// <summary>
     116        /// When the Input-Slot changed, set this variable to true, so the new Stream will be transformed to byte[]
     117        /// </summary>
     118        private bool cryptoolStreamChanged = false;
     119        private byte[] decryptedByteData;
     120        private byte[] GetByteFromCryptoolStream(CryptoolStream cryptoolStream)
     121        {
     122            // only transform CryptoolStream to Byte[], if there is a new CryptoolStream
     123            // or decryptedByteData is Null
     124            if (cryptoolStreamChanged || decryptedByteData == null)
     125            {
     126                CryptoolStream cs = new CryptoolStream();
     127                cs.OpenRead(cryptoolStream.FileName);
     128                decryptedByteData = new byte[cs.Length];
     129                if(cs.Length > Int32.MaxValue)
     130                    throw(new Exception("CryptoolStream length is longer than the Int32.MaxValue"));
     131                cs.Read(decryptedByteData, 0, (int)cs.Length);
     132            }
     133            return decryptedByteData;
     134        }
     135
     136        byte[] initVector;
     137        [PropertyInfo(Direction.InputData, "Initialization Vector", "Initialization vector with which the data were encrypted", "", DisplayLevel.Beginner)]
     138        public byte[] InitVector
     139        {
     140            get { return this.initVector; }
     141            set
     142            {
     143                if (value != this.initVector)
     144                {
     145                    this.initVector = value;
     146                    OnPropertyChanged("InitVector");
     147                }
     148            }
     149        }
     150        /* END: Lines above are from Arnie - 2010.01.12 */
     151
     152        #endregion
     153
    95154        #region IPlugin Members
    96155
     
    130189        }
    131190
     191        // because Encryption PlugIns were changed radical, the new StartPoint is here - Arnie 2010.01.12
    132192        public void Execute()
    133193        {
     194            if (this.DecryptedData != null) //to prevent execution on initialization
     195            {
     196                if (this.ControlMaster != null)
     197                    this.process(this.ControlMaster);
     198                else
     199                {
     200                    GuiLogMessage("You have to connect the KeySearcher with the Decryption Control!", NotificationLevel.Warning);
     201                }
     202            }
    134203        }
    135204
     
    345414            try
    346415            {
    347                 valueKey.decryption = sender.Decrypt(keya, bytesToUse);
     416                byte[] decryptedData = GetByteFromCryptoolStream(this.DecryptedData);
     417                valueKey.decryption = sender.Decrypt(decryptedData, keya);
     418                //valueKey.decryption = sender.Decrypt(keya, bytesToUse);
    348419            }
    349420            catch (Exception ex)
     
    716787        protected virtual void onStatusChanged(IControl sender, bool readyForExecution)
    717788        {
     789            // doesn't work anymore, because Encryption PlugIns were changed radical!!! Arnie 2010.01.12
    718790            if (readyForExecution)
    719791            {
Note: See TracChangeset for help on using the changeset viewer.