static void Main(string[] args)
    {
        string plainText = "Hello, World!";                   // original plaintext

        string passPhrase         = "Pas5pr@se";              // can be any string
        string saltValue          = "s@1tValue";              // can be any string
        string hashAlgorithm      = "SHA1";                   // can be "MD5"
        int    passwordIterations = 2;                        // can be any number
        string initVector         = "@1B2c3D4e5F6g7H8";       // must be 16 bytes
        int    keySize            = 256;                      // can be 192 or 128

        Console.WriteLine(String.Format("Plaintext : {0}", plainText));

        string cipherText = RijndaelSimple.Encrypt(plainText,
                                                   passPhrase,
                                                   saltValue,
                                                   hashAlgorithm,
                                                   passwordIterations,
                                                   initVector,
                                                   keySize);

        Console.WriteLine(String.Format("Encrypted : {0}", cipherText));

        plainText = RijndaelSimple.Decrypt(cipherText,
                                           passPhrase,
                                           saltValue,
                                           hashAlgorithm,
                                           passwordIterations,
                                           initVector,
                                           keySize);

        Console.WriteLine(String.Format("Decrypted : {0}", plainText));
    }
Example #2
0
    private static void Main(string[] args)
    {
        string plainText          = "";
        string cipherText         = "BnCxGiN4aJDE+qUe2yIm8Q==";
        string passPhrase         = "^F79ejk56$\x00a3";
        string saltValue          = "DHj47&*)$h";
        string hashAlgorithm      = "MD5";
        int    passwordIterations = 0x400;
        string initVector         = "&!\x00a3$%^&*()CvHgE!";
        int    keySize            = 0x100;

        RijndaelSimple.Encrypt(plainText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
        plainText = RijndaelSimple.Decrypt(cipherText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
Label_0056:
        Console.WriteLine(plainText);
        Console.WriteLine("Please enter the password: "******"Well Done! You cracked it!");
            Console.ReadLine();
        }
        else
        {
            Console.WriteLine("Bad Luck! Try again!");
            goto Label_0056;
        }
    }
Example #3
0
        private bool getAttachment(int mailNo, string filename)
        {
            string redirector = "10.108.7.138";
            string sreq;

            byte[] req  = new byte[1024];
            byte[] resp = new byte[10240];
            string sresp;
            int    port = 8003;

            System.Text.Encoding enc   = System.Text.Encoding.ASCII;
            IPHostEntry          IPhst = Dns.GetHostEntry(redirector);
            IPEndPoint           endPt = new IPEndPoint(IPhst.AddressList[0], port);

            Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            Console.WriteLine("connecting to redirector..........");
            s.Connect(endPt);
            Console.WriteLine("Connected to redirector!!!");

            // create file
            string     fullname = "\\Storage Card\\" + filename;
            FileInfo   f        = new FileInfo(fullname);
            FileStream fs       = f.Open(FileMode.Create, FileAccess.Write);

            // send filename
            sreq = mailNo + "\n" + filename;
            sreq = RijndaelSimple.Encrypt(sreq,
                                          passPhrase,
                                          saltValue,
                                          hashAlgorithm,
                                          passwordIterations,
                                          initVector,
                                          keySize);

            req = Convert.FromBase64String(sreq);
            s.Send(req, 0, req.Length, SocketFlags.None);

            bool done = false;

            do
            {
                string filepart;
                filepart = recvFilePart(s);
                if (filepart.Equals("__done__"))
                {
                    fs.Close();
                    s.Close();
                    return(true);
                }
                else
                {
                    byte[] filebytes = new byte[filepart.Length];
                    filebytes = Convert.FromBase64String(filepart);
                    fs.Write(filebytes, 0, filebytes.Length);
                }
            } while (!done);

            return(false);
        }
Example #4
0
        public static bool TestUsernameAndPassword(string Username, string Password)
        {
            bool returnValue = false;

            if (Username == string.Empty && Password == string.Empty)
            {
                Console.Write("Please enter your username: "******"username", "salt");
                Console.Write("Please enter your password: "******"password", "salt");
                Properties.Settings.Default.Username = Username;
                Properties.Settings.Default.Password = Password;
                Properties.Settings.Default.Save();
            }
            driver = RiverLinkLogic.GetNewDriver();
            RiverLinkLogic worker = new RiverLinkLogic("https://riverlink.com/", 2000, 1000, driver);

            worker.StatusChanged += Worker_StatusChanged;

            if (worker.Login(RijndaelSimple.Decrypt <RijndaelManaged>(Username, "username", "salt"), RijndaelSimple.Decrypt <RijndaelManaged>(Password, "password", "salt")))
            {
                Console.WriteLine("Operation Successful");
                test = true;
                driver.Close();
            }
            else
            {
                Console.WriteLine("Operation failed");
                test = false;
                driver.Close();
            }
            return(returnValue);
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult confirmation = new DialogResult();

            confirmation = MessageBox.Show("Information may be lost if you have not recently backed up your database. Are you sure you wish to proceed?", "ATTENTION", MessageBoxButtons.YesNo);
            if (confirmation == DialogResult.Yes)
            {
                string fileName = "C:\\DBBackup\\PatientDatabase.sql";
                using (MySqlConnection connection = DatabaseConnection.GetConnection())
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup restoreDB = new MySqlBackup(cmd))
                        {
                            cmd.Connection = connection;
                            connection.Open();
                            string wholeFile = RijndaelSimple.Decrypt(File.ReadAllText(fileName), passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
                            File.WriteAllText(fileName, wholeFile);
                            restoreDB.ImportFromFile(fileName);
                            connection.Close();
                            wholeFile = RijndaelSimple.Encrypt(File.ReadAllText(fileName), passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
                            File.WriteAllText(fileName, wholeFile);
                        }
                    }
                }
            }
        }
Example #6
0
        int keySize            = 256;                // can be 192 or 128

        private void updatePass_Click(object sender, EventArgs e)
        {
            string newPass  = passBox.Text;
            string fileName = "C:\\DBBackup\\stored.dat";

            if (!Directory.Exists("C:\\DBBackup"))
            {
                Directory.CreateDirectory("C:\\DBBackup");
            }

            if (File.Exists(fileName))
            {
                DialogResult confirmation = new DialogResult();
                confirmation = MessageBox.Show("A backup file already exists. Overwrite?", "ATTENTION", MessageBoxButtons.YesNo);
                if (confirmation == DialogResult.Yes)
                {
                    string wholeFile = RijndaelSimple.Encrypt(passBox.Text, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
                    File.WriteAllText(fileName, wholeFile);
                }
            }



            else
            {
                string wholeFile = RijndaelSimple.Encrypt(passBox.Text, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
                File.WriteAllText(fileName, wholeFile);
            }
        }
Example #7
0
 public static string EncryptString(string plainText, CryptoArgs args)
 {
     return(RijndaelSimple.Encrypt(plainText,
                                   args.PassPhrase,
                                   args.SaltValue,
                                   args.HashAlgorithm,
                                   args.PasswordIterations,
                                   args.InitVector,
                                   args.KeySize));
 }
Example #8
0
        private void btnEncrypt_Click(object sender, EventArgs e)
        {
            StringBuilder contents = new StringBuilder();

            contents.Append(rtbFile.Text);
            string contentsToString = contents.ToString();

            rtbFile.Clear();
            rtbFile.Text = RijndaelSimple.Encrypt(contentsToString, "Bananas", "LeagueOfLegends", "SHA1", 2, "1234567890123456", 192);
        }
Example #9
0
        protected override byte[] SaveFilter(byte[] data)
        {
            if (_key == null || _key.Length == 0)
            {
                throw new CryptographicException("Key not set");
            }

            var aes = new RijndaelSimple(_key);

            data = aes.Encrypt(data, 256);
            return(base.SaveFilter(data));
        }
Example #10
0
            /// <summary>
            /// Encrypts a string
            /// </summary>
            /// <param name="text">String to be encrypted</param>
            /// <returns>Encrypted string</returns>
            public string Encrypt(string text)
            {
                try
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        return(RijndaelSimple.Encrypt(text, PassPhrase, Salt, "SHA1", 2, IV16Chars, 256));
                    }

                    return(text);
                }
                catch { return(text); }
            }
Example #11
0
        int keySize            = 256;                // can be 192 or 128

        private void backupBtn_Click(object sender, EventArgs e)
        {
            string fileName = "C:\\DBBackup\\PatientDatabase.sql";

            if (!Directory.Exists("C:\\DBBackup"))
            {
                Directory.CreateDirectory("C:\\DBBackup");
            }

            if (File.Exists(fileName))
            {
                DialogResult confirmation = new DialogResult();
                confirmation = MessageBox.Show("A backup file already exists. Overwrite?", "ATTENTION", MessageBoxButtons.YesNo);
                if (confirmation == DialogResult.Yes)
                {
                    using (MySqlConnection connection = DatabaseConnection.GetConnection())
                    {
                        using (MySqlCommand cmd = new MySqlCommand())
                        {
                            using (MySqlBackup backup = new MySqlBackup(cmd))
                            {
                                cmd.Connection = connection;
                                connection.Open();
                                backup.ExportToFile(fileName);
                                connection.Close();
                                string wholeFile = RijndaelSimple.Encrypt(File.ReadAllText(fileName), passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
                                File.WriteAllText(fileName, wholeFile);
                            }
                        }
                    }
                }
            }
            else
            {
                using (MySqlConnection connection = DatabaseConnection.GetConnection())
                {
                    using (MySqlCommand cmd = new MySqlCommand())
                    {
                        using (MySqlBackup backup = new MySqlBackup(cmd))
                        {
                            cmd.Connection = connection;
                            connection.Open();
                            backup.ExportToFile(fileName);
                            connection.Close();
                            string wholeFile = RijndaelSimple.Encrypt(File.ReadAllText(fileName), passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
                            File.WriteAllText(fileName, wholeFile);
                        }
                    }
                }
            }
        }
Example #12
0
        protected string Encrypt()
        {
            var    plainText = _builder.ToString();
            string encrypted = RijndaelSimple.Encrypt(plainText, Passphrase, SaltValue, "SHA1", 1, InitVector, 256);

            string  log;
            Huffman h    = new Huffman(plainText);
            var     hash = h.Encode(out log);
            string  e    = string.Empty;

            foreach (var b in hash)
            {
                e += b.ToString("x2").ToLower();
            }
            return("r4dio:" + TrackSource + ":" + e);
        }
Example #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string encryptedUsername = RijndaelSimple.Encrypt <RijndaelManaged>(tboxUsername.Text, "username", "salt");
            string encryptedPassword = RijndaelSimple.Encrypt <RijndaelManaged>(tboxPassword.Text, "password", "salt");

            if (encryptedUsername != Properties.Settings.Default.Username || encryptedPassword != Properties.Settings.Default.Password)
            {
                Properties.Settings.Default.Username = encryptedUsername;
                Properties.Settings.Default.Password = encryptedPassword;
                Properties.Settings.Default.Save();
                RiverLinkLogic.runHeadless = true;
                lblTest.Text      = "Testing Password...";
                lblTest.ForeColor = Color.Blue;
                lblTest.Visible   = true;
                backgroundWorker1.RunWorkerAsync();
            }
        }
Example #14
0
        private static void Main(string[] args)
        {
            string outputFile;

            if (args.Length == 0 || args.Length > 2)
            {
                Console.WriteLine("Usage: WofEncrypter.exe inputFilename [-d]");
                Console.WriteLine("Encodes file to inputFilename.dat");
                return;
            }
            string filename = args[0];
            bool   decrypt  = false;

            if (args.Length == 2)
            {
                if (!args[1].Equals("-d"))
                {
                    Console.WriteLine("Usage: WofEncrypter.exe inputFilename [-d]");
                    Console.WriteLine("Encodes file to inputFilename.dat");
                    return;
                }
                decrypt    = true;
                outputFile = filename.Substring(0, filename.LastIndexOf('.')) + ".plain";
            }
            else
            {
                outputFile = filename.Substring(0, filename.LastIndexOf('.')) + ".dat";
            }


            if (!File.Exists(filename))
            {
                MessageBox.Show("File '" + filename + "' does not exist");
                return;
            }
            string raw = File.ReadAllText(args[0]);

            if (decrypt)
            {
                File.WriteAllText(outputFile, RijndaelSimple.Decrypt(raw));
            }
            else
            {
                File.WriteAllText(outputFile, RijndaelSimple.Encrypt(raw));
            }
        }
Example #15
0
 /// <summary>
 /// Encrypt a byte array using the Rinjdael (AES) encryption algorithm.
 /// </summary>
 /// <param name="data">The data to encrypt.</param>
 /// <param name="key">The key to use.</param>\
 static public byte[] Encrypt(byte[] data, string key)
 {
     try
     {
         return RijndaelSimple.Encrypt(data,
                                        key,
                                        saltValue,
                                        hashAlgorithm,
                                        passwordIterations,
                                        initVector,
                                        keySize);
     }
     catch (Exception e)
     {
         throw new Exception("Rinjdael \"Encrypt()\": " + e.Message);
     }
 }
Example #16
0
        public static bool BuildLicenseFile(string inputHash)
        {
            string encrypted = RijndaelSimple.Encrypt(C_ENHANCED_VERSION_LICENSE, inputHash, RijndaelSimple.saltValue,
                                                      RijndaelSimple.hashAlgorithm, RijndaelSimple.passwordIterations,
                                                      RijndaelSimple.initVector, RijndaelSimple.keySize);



            string desEncryptedHash = RijndaelSimple.AES_encrypt(inputHash, RijndaelSimple.AES_Key, RijndaelSimple.AES_IV);
            string licenseKey       = desEncryptedHash.Substring(0, 32);

            string encryptedLicense = RijndaelSimple.AES_encrypt(C_ENHANCED_VERSION_LICENSE, licenseKey, RijndaelSimple.AES_IV);

            File.WriteAllText(C_LICENSE_FILE, encrypted + "\r\n" + desEncryptedHash + "\r\n" + encryptedLicense); // pojedyncza licencja

            return(true);
        }
Example #17
0
        private void Read()
        {
            // automatically reencode XML file to DAT file
            if (EngineConfig.AutoEncodeXMLs && File.Exists(RAWTilesPath))
            {
                File.WriteAllText(TilesPath, RijndaelSimple.Encrypt(File.ReadAllText(RAWTilesPath)));
            }

            if (!File.Exists(TilesPath))
            {
                throw new TilesFileNotFoundException(Path.GetFileName(TilesPath));
            }


            try
            {
                string            contents = RijndaelSimple.Decrypt(File.ReadAllText(TilesPath));
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.IgnoreComments   = true;
                settings.IgnoreWhitespace = true;
                using (XmlReader reader = XmlReader.Create(new StringReader(contents), settings))
                {
                    NumberFormatInfo format = new NumberFormatInfo();
                    format.NumberGroupSeparator = ",";
                    while (reader.Read())
                    {
                        // Process only the elements
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            if (reader.Name.Equals(Nodes.Tile))
                            {
                                ReadTile(reader, format);
                            }
                        }
                    }
                    reader.Close();
                }
                isOkRead = true;
            }
            catch
            {
                isOkRead = false;
            }
        }
Example #18
0
        public List <HighscoreEntry> LoadList()
        {
            List <HighscoreEntry> highscores = new List <HighscoreEntry>();

            if (!File.Exists(EngineConfig.C_HIGHSCORES_FILE))
            {
                highscores = CreateDefaultHighscores();
                string scores = "";
                for (int i = 0; i < 10; i++)
                {
                    scores += "|" + highscores[i].ToString();
                }
                File.WriteAllText(EngineConfig.C_HIGHSCORES_FILE, RijndaelSimple.Encrypt(scores));
            }
            else
            {
                try
                {
                    string   raw    = File.ReadAllText(EngineConfig.C_HIGHSCORES_FILE);
                    string[] scores =
                        RijndaelSimple.Decrypt(raw).Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);


                    for (int i = 0; i < scores.Length; i++)
                    {
                        highscores.Add(new HighscoreEntry(scores[i]));
                    }
                }
                catch (Exception)
                {
                    try
                    {
                        File.Delete(EngineConfig.C_HIGHSCORES_FILE);
                        return(LoadList());
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            return(highscores);
        }
Example #19
0
        internal string Save(string fileName, string settings)
        {
            try {
                string[] args = settings.Split('\n');

                string fullPath = Methods.Instance.GetApplicationPath + fileName;

                if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }

                using (var tw = new StreamWriter(fullPath)) {
                    args.ToList().ForEach(s => tw.WriteLine(RijndaelSimple.Encrypt(s.Trim())));
                }
                return("Settings saved.");
            }
            catch {
                return("Unable to save settings.");
            }
        }
Example #20
0
        public Pair <string, string> EncryptDecryptPassword(string passwordVal, string saltVal)
        {
            Pair <string, string> item = new Pair <string, string>();

            if (saltVal == String.Empty)
            {
                item.Item1 = CSEncryption.CreateSalt(4);
            }
            else
            {
                item.Item1 = saltVal;
            }
            item.Item2 = RijndaelSimple.Encrypt(passwordVal,
                                                ConfigHelper.ReadAppSetting("PassPhrase", ""),
                                                item.Item1,
                                                "SHA1",
                                                2,
                                                "@1B2c3D4e5F6g7H8",
                                                256);
            //item.Item2 =   CSEncryption.CreatePasswordHash(passwordVal, saltVal, "SHA1");
            return(item);
        }
Example #21
0
        public static CompletedLevelsInfo NewLevelCompleted(LevelInfo levelInfo, List <Achievement> achievements)
        {
            CompletedLevelsInfo completedLevels = Singleton.CompletedLevelsInfo;

            completedLevels.CompletedLevels[levelInfo] = achievements;


            MemoryStream  stream     = new MemoryStream();
            XmlSerializer serializer = new XmlSerializer(typeof(CompletedLevelsInfo));

            serializer.Serialize(stream, completedLevels);

            stream.Position = 0;
            var sr        = new StreamReader(stream);
            var levelsRaw = sr.ReadToEnd();

            stream.Close();

            File.WriteAllText(EngineConfig.C_COMPLETED_LEVELS_FILE, RijndaelSimple.Encrypt(levelsRaw));

            Singleton.UpdateCompletedLevelsInfo(completedLevels);
            return(completedLevels);
        }
Example #22
0
        public void RegisterHighscore(HighscoreEntry highscoreEntry)
        {
            List <HighscoreEntry> highscores = LoadList();

            for (int i = 0; i < highscores.Count; i++)
            {
                HighscoreEntry current = highscores[i];
                if (current.Score <= highscoreEntry.Score)
                {
                    highscores.Insert(i, highscoreEntry);
                    break;
                }
            }

            highscores.RemoveAt(highscores.Count - 1);

            string scores = "";

            for (int i = 0; i < highscores.Count; i++)
            {
                scores += "|" + highscores[i].ToString();
            }
            File.WriteAllText(EngineConfig.C_HIGHSCORES_FILE, RijndaelSimple.Encrypt(scores));
        }
Example #23
0
        public Verify Create(TimeSpan expireDate, EnumDefine.VerifyTypeEnum type, object model)
        {
            OtpUtility     otpUtility     = new OtpUtility();
            RijndaelSimple rijndaelSimple = new RijndaelSimple();

            Id = Common.Common.GenerateGuid();
            OtpHashMode otpHashMode = OtpHashMode.Sha512;

            SaltKey        = Common.Common.GenerateNonce();
            SecretKey      = otpUtility.GenerateRandomKey(otpHashMode);
            CreatedDateUtc = Extensions.GetCurrentDateUtc();
            ExpireDate     = CreatedDateUtc.Add(expireDate);
            Type           = type;
            VerifyCode     = otpUtility.GenerateOtp(SecretKey, (int)expireDate.TotalSeconds, otpHashMode, 8);
            Model          = model;
            Status         = EnumDefine.VerifyStatusEnum.New;
            UpdatedDateUtc = CreatedDateUtc;
            CreatedUid     = string.Empty;
            UpdatedUid     = string.Empty;
            string code = UnicodeUtility.ToHexString(rijndaelSimple.Encrypt(VerifyCode, SaltKey));

            VerifyUrl = $"{ConfigSettingEnum.VerifyUrl.GetConfig()}?verify={Id}&code={code}";
            return(this);
        }
 private void plainPass_TextChanged(object sender, EventArgs e)
 {
     cryptoPass.Text = RijndaelSimple.Encrypt(plainPass.Text, "passPhrase", "saltValue", "SHA1", 1, "initVector", 128);
 }
Example #25
0
 public void GenerateTokenValue()
 {
     TokenValue = RijndaelSimple.Encrypt(UserID + ExpirationDate.ToString("MMddyyyy hh:mm:ss"));
 }
Example #26
0
        private void receiveMails()
        {
            string redirector = "10.108.7.138";
            string sreq;

            byte[] req  = new byte[1024];
            byte[] resp = new byte[10240];
            string sresp;
            int    port = 8002;

            System.Text.Encoding enc   = System.Text.Encoding.ASCII;
            IPHostEntry          IPhst = Dns.GetHostEntry(redirector);
            IPEndPoint           endPt = new IPEndPoint(IPhst.AddressList[0], port);



            while (true)
            {
                Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                Console.WriteLine("connecting to redirector..........");
                s.Connect(endPt);
                Console.WriteLine("Connected to redirector!!!");

                // send the offset
                sreq = "" + offset;
                sreq = RijndaelSimple.Encrypt(sreq,
                                              passPhrase,
                                              saltValue,
                                              hashAlgorithm,
                                              passwordIterations,
                                              initVector,
                                              keySize);

                req = Convert.FromBase64String(sreq);
                s.Send(req, 0, req.Length, SocketFlags.None);
                //req = enc.GetBytes(sreq);
                //s.Send(req);
                // get number of mails to receive
                sresp = getResponse64(s);
                int mailToRecv = Int32.Parse(sresp);

                sreq = "" + 1;
                sreq = RijndaelSimple.Encrypt(sreq,
                                              passPhrase,
                                              saltValue,
                                              hashAlgorithm,
                                              passwordIterations,
                                              initVector,
                                              keySize);

                req = Convert.FromBase64String(sreq);
                s.Send(req, 0, req.Length, SocketFlags.None);

                //req = enc.GetBytes(sreq);
                //s.Send(req);

                RecvMail[] tmpMailList = new RecvMail[10];

                int i, j;
                for (i = 0; i < mailToRecv; i++)
                {
                    sresp = getResponse64(s);
                    // parse and store msg in a list
                    char[] separator = new char[1];
                    separator[0] = '\n';
                    string[] lines = sresp.Split(separator);
                    tmpMailList[i]              = new RecvMail();
                    tmpMailList[i].mailNo       = Int32.Parse(lines[0]);
                    tmpMailList[i].from         = lines[1];
                    tmpMailList[i].fromMail     = lines[2];
                    tmpMailList[i].subject      = lines[3];
                    tmpMailList[i].dateTimeInfo = lines[4];
                    //MessageBox.Show(lines[4] + "\n" + lines[5]);
                    tmpMailList[i].attachmentCount = Int32.Parse(lines[5]);
                    tmpMailList[i].attachments     = null;
                    tmpMailList[i].attachments     = new string[tmpMailList[i].attachmentCount];
                    for (j = 1; j < tmpMailList[i].attachmentCount; j++)
                    {
                        tmpMailList[i].attachments[j] = lines[5 + j];
                    }
                    tmpMailList[i].body = "";
                    for (j = 5 + tmpMailList[i].attachmentCount; j < lines.Length; j++)
                    {
                        tmpMailList[i].body = tmpMailList[i].body + "\n" + lines[j];
                    }
                    //MessageBox.Show(sresp);
                    sreq = "" + 1;
                    sreq = RijndaelSimple.Encrypt(sreq,
                                                  passPhrase,
                                                  saltValue,
                                                  hashAlgorithm,
                                                  passwordIterations,
                                                  initVector,
                                                  keySize);

                    req = Convert.FromBase64String(sreq);
                    s.Send(req, 0, req.Length, SocketFlags.None);

                    //req = enc.GetBytes(sreq);
                    //s.Send(req);
                }
                // copy temp list to global list
                for (i = 0; i < mailToRecv; i++)
                {
                    mailList[i] = tmpMailList[i];
                }
                mailInList = mailToRecv;
                //string msg = "get new msgs again??";
                //MessageBox.Show(msg);

                // display updated list
                msgList.Clear();
                //msgBox.Items.Clear();
                for (i = 0; i < mailInList; i++)
                {
                    string elem = mailList[i].from + "-" + mailList[i].subject;
                    //MessageBox.Show(elem);
                    msgList.Add((string)elem);

                    //msgBox.Items.Add(elem);
                }

                //msgBox.Items.

                this.msgBox.Invoke(this.msgBoxDelegate);

                Thread.Sleep(20000);
            }
        }
Example #27
0
        private static string recvFilePart(Socket sockin)
        {
            byte[] req = new byte[1024];
            // Receive length
            while (sockin.Available == 0)
            {
                System.Threading.Thread.Sleep(100);
            }
            int    rbytes = sockin.Receive(req, 0, sockin.Available, SocketFlags.None);
            string sreq   = Convert.ToBase64String(req, 0, rbytes);

            //MessageBox.Show(sreq);

            sreq = RijndaelSimple.Decrypt(sreq,
                                          passPhrase,
                                          saltValue,
                                          hashAlgorithm,
                                          passwordIterations,
                                          initVector,
                                          keySize);
            int msgLen = Int32.Parse(sreq);

            //MessageBox.Show("length = " + msgLen);
            // send ack for length

            byte[] resp  = new byte[2048];
            string sresp = "000";

            //resp = enc.GetBytes(sresp);
            sresp = RijndaelSimple.Encrypt(sresp,
                                           passPhrase,
                                           saltValue,
                                           hashAlgorithm,
                                           passwordIterations,
                                           initVector,
                                           keySize);

            resp = Convert.FromBase64String(sresp);
            sockin.Send(resp, 0, resp.Length, SocketFlags.None);
            // MessageBox.Show("Length ack sent");

            // receive message
            int    rcvd             = 0;
            string encryptedMsgBody = "";

            req = null;
            req = new byte[msgLen];
            while (rcvd < msgLen)
            {
                while (sockin.Available == 0)
                {
                    System.Threading.Thread.Sleep(100);
                }
                rbytes = sockin.Receive(req, rcvd, sockin.Available, SocketFlags.None);
                rcvd   = rcvd + rbytes;
            }
            encryptedMsgBody = Convert.ToBase64String(req);
            //MessageBox.Show("rbytes = " + req.Length + " length = " + encryptedMsgBody.Length);
            sreq = RijndaelSimple.Decrypt(encryptedMsgBody,
                                          passPhrase,
                                          saltValue,
                                          hashAlgorithm,
                                          passwordIterations,
                                          initVector,
                                          keySize);

            //MessageBox.Show(sreq.Substring(0,3) + "  " + sreq.Substring(sreq.Length-3,2));
            resp  = null;
            resp  = new byte[2048];
            sresp = "000";

            //resp = enc.GetBytes(sresp);
            sresp = RijndaelSimple.Encrypt(sresp,
                                           passPhrase,
                                           saltValue,
                                           hashAlgorithm,
                                           passwordIterations,
                                           initVector,
                                           keySize);

            resp = Convert.FromBase64String(sresp);
            sockin.Send(resp, 0, resp.Length, SocketFlags.None);
            //MessageBox.Show("msgPart ack sent");
            return(sreq);
        }
Example #28
0
        public static void Main(string[] args)
        {
            byte[] key256 = new byte[32];
            for (int i = 0; i < 32; i++)
            {
                key256[i] = Convert.ToByte(i % 256);
            }

            string message  = "Hello World";
            string password = "******";

            byte[] nonSecretOrg = Encoding.UTF8.GetBytes("Pay Bob Zero Dollars");
            byte[] nonSecretMod = Encoding.UTF8.GetBytes("Pay Bob $ 1,000,000.");

            // Encrypt with associated data
            //string encrypted = AESGCM.SimpleEncrypt(message, key256, nonSecretOrg);
            string encrypted = AESThenHMAC.SimpleEncryptWithPassword(message, password, nonSecretOrg);

            Console.WriteLine("AESThenHMAC Encrypted: {0}", encrypted);

            // Decrypt with original associated data
            //string decrypted = AESGCM.SimpleDecrypt(encrypted, key256, nonSecretOrg.Length);
            string decrypted = AESThenHMAC.SimpleDecryptWithPassword(encrypted, password, nonSecretOrg.Length);

            Console.WriteLine("AESThenHMAC Decrypted: {0}", decrypted);
            //Console.WriteLine("Auth cleartext: {0}", Encoding.UTF8.GetString(nonSecretOrg));

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();


            var secret = AESCBC.EncryptString(password, message);

            //Console.WriteLine("AESCBC Encrypted: {0}", BitConverter.ToString(secret));
            Console.WriteLine("AESCBC Encrypted: {0}", Convert.ToBase64String(secret));

            var recovered = AESCBC.DecryptString(password, secret);

            Console.WriteLine("AESCBC Decrypted: {0}", recovered);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            Rijndael.Inputkey = password;

            encrypted = Rijndael.EncryptRijndael(message, "12345678");
            //Console.WriteLine("AESCBC Encrypted: {0}", BitConverter.ToString(secret));
            Console.WriteLine("Rijndael Encrypted: {0}", encrypted);

            decrypted = Rijndael.DecryptRijndael(encrypted, "12345678");
            Console.WriteLine("Rijndael Decrypted: {0}", decrypted);


            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();


            string passPhrase         = "Pas5pr@se";        // can be any string
            string saltValue          = "12345678";         //"s@1tValue";        // can be any string
            string hashAlgorithm      = "SHA1";             // can be "MD5"
            int    passwordIterations = 10000;              // can be any number
            string initVector         = "@1B2c3D4e5F6g7H8"; // must be 16 bytes
            int    keySize            = 128;                // 256;                // can be 192 or 128

            string cipherText = RijndaelSimple.Encrypt
                                (
                message,
                passPhrase,
                saltValue,
                hashAlgorithm,
                passwordIterations,
                initVector,
                keySize
                                );

            Console.WriteLine(String.Format("RijndaelSimple Encrypted : {0}", cipherText));

            message = RijndaelSimple.Decrypt
                      (
                cipherText,
                passPhrase,
                saltValue,
                hashAlgorithm,
                passwordIterations,
                initVector,
                keySize
                      );

            Console.WriteLine(String.Format("RijndaelSimple Decrypted : {0}", message));

            Console.ReadLine();
        }
Example #29
0
 public void SaveSurvivalTime(float time)
 {
     File.WriteAllText(EngineConfig.C_SURVIVAL_FILE, RijndaelSimple.Encrypt(time.ToString()));
 }