Esempio n. 1
0
        /// <summary>
        /// save Data to File
        /// </summary>
        /// <param name="FileName">the FileName to use for save</param>
        /// <param name="FileVersion">optional File-Version to apply - use "" to apply DLL-Version</param>
        /// <returns>TRUE on success, FALSE on error</returns>
        private bool _SaveToFile(string FileName, string FileVersion)
        {
            // something set in FileName? Exit if not...
            if (FileName.Trim() == "")
            {
                return(false);
            }
            DDPro.Software.Net20.Library.Rijndael _cipher = new DDPro.Software.Net20.Library.Rijndael(System.Text.Encoding.UTF8);
            // get dataset-data
            string        _innerXML = _int_DataSet.GetXml();
            StringBuilder _FileCont = new StringBuilder();

            _FileCont.AppendLine("CUX = Ciphered User XML");
            // set File-Version by Assembly-Number
            if (FileVersion == "")  // no Version specified - use DLL-Version
            {
                _FileCont.AppendLine("Version = " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString());
            }
            else // Version is specified
            {
                _FileCont.AppendLine("Version = " + FileVersion);
            }
            _FileCont.AppendLine("Index = " + _set_IdxMode.ToString()); // specify used index
            _FileCont.AppendLine("-| start |-");                        // set StartData-Tag
            // start Data-Block
            string _cDat = _cipher.EasyEncrypt(_innerXML, _set_DataCipherPhrase);
            // add linebreak every 60 signs in Data
            long   _strLen    = _cDat.Length;
            double _runCycles = (_strLen / 60);
            int    _runs      = Convert.ToInt32(Math.Floor(_runCycles));

            for (long i = 0; i <= _runs; i++)
            {
                if ((i * 60) > int.MaxValue)                                        // if not "runable" cycle
                {
                    return(false);                                                  // exit on too many cycles
                }
                if (i == _runs)                                                     // last cycle - take the rest
                {
                    _FileCont.AppendLine(_cDat.Substring(Convert.ToInt32(i * 60))); // add 60 signs
                }
                else // regular cycle - write 60 signs
                {
                    _FileCont.AppendLine(_cDat.Substring(Convert.ToInt32(i * 60), 60));       // add 60 signs
                }
            }
            // end Data-Block
            _FileCont.AppendLine("-| end |-");
            // _FileCont.AppendLine( "" ); // 4 debug
            // _FileCont.AppendLine( _cDat ); // 4 debug
            // write data to file
            if (!_fileWriter(FileName, _FileCont.ToString()))
            {
                return(false);
            }
            // everything has worked, data is saved
            _int_DataSet.AcceptChanges(); // remind save
            return(true);
        }
Esempio n. 2
0
        public void test_RijndaelAES()
        {
            DDPro.Software.Net20.Library.Rijndael _testObject = new DDPro.Software.Net20.Library.Rijndael(Encoding.Default);
            Assert.NotNull(_testObject, "AES-Class for Test test_RijndaelAES could no be created...");
            string _pw  = "Pa$$Phra53!";
            string _msg = "Message to cipher...";
            string _tmp = "";

            // check one cycle
            _tmp = _testObject.EasyEncrypt(_msg, _pw);
            Assert.AreEqual(_msg, _testObject.EasyDecrypt(_tmp, _pw), "test_RijndaelAES: encrypted String (1 cycle) not decrypted to original...");
            Assert.AreNotEqual(_msg, _testObject.EasyDecrypt(_tmp, "wrongPW"), "test_RijndaelAES: encrypted String (1 cycle) decrypted to original with wrong password --> error...");

            // check five cycles
            _tmp = _testObject.EasyEncrypt(_msg, _pw, 5);
            Assert.AreNotEqual(_msg, _testObject.EasyDecrypt(_tmp, _pw, 4), "test_RijndaelAES: encrypted String (5 cycles) decrypted to original with 4 cycles --> error...");
            Assert.AreEqual(_msg, _testObject.EasyDecrypt(_tmp, _pw, 5), "test_RijndaelAES: encrypted String (5 cycles) not decrypted to original...");
        }