Exemple #1
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);
        }
Exemple #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;
        }
    }
Exemple #3
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);
                        }
                    }
                }
            }
        }
    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));
    }
Exemple #5
0
        private static string getResponse64(Socket s)
        {
            string sResponse;
            int    response;

            byte[] bytes = new byte[2048];
            while (s.Available == 0)
            {
                System.Threading.Thread.Sleep(100);
            }

            int recvd = s.Receive(bytes, 0, s.Available, SocketFlags.None);

            //sResponse = Encoding.ASCII.GetString(bytes, 0, (int)bytes.Length);
            //sResponse = Convert.ToBase64String(bytes);
            sResponse = Convert.ToBase64String(bytes, 0, recvd);
            //MessageBox.Show("len = " + recvd + "\n" + sResponse);
            sResponse = RijndaelSimple.Decrypt(sResponse,
                                               passPhrase,
                                               saltValue,
                                               hashAlgorithm,
                                               passwordIterations,
                                               initVector,
                                               keySize);

            //MessageBox.Show(sResponse);

            return(sResponse);
        }
Exemple #6
0
        public int Validate(string username, string password)
        {
            Triplet <string, string, int> pairVal = CustomerDAL.ValidateUser(username);

            if (pairVal.Item1 != String.Empty)
            {
                string saltValue  = pairVal.Item2;
                string decryptVal = RijndaelSimple.Decrypt(pairVal.Item1,
                                                           ConfigHelper.ReadAppSetting("PassPhrase", ""),
                                                           saltValue,
                                                           "SHA1",
                                                           2,
                                                           "@1B2c3D4e5F6g7H8",
                                                           256);;
                if (password == decryptVal)
                {
                    return(pairVal.Item3);
                }
                else
                {
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
Exemple #7
0
 public static string DecryptString(string encryptedText, CryptoArgs args)
 {
     return(RijndaelSimple.Decrypt(encryptedText,
                                   args.PassPhrase,
                                   args.SaltValue,
                                   args.HashAlgorithm,
                                   args.PasswordIterations,
                                   args.InitVector,
                                   args.KeySize));
 }
Exemple #8
0
        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            StringBuilder contents = new StringBuilder();

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

            rtbFile.Clear();
            rtbFile.Text = RijndaelSimple.Decrypt(contentsToString, "Bananas", "LeagueOfLegends", "SHA1", 2, "1234567890123456", 192);
        }
        public OracleDataImport(Landing_Table Table, int ExecutionId, LandingRepository Repository)
        {
            String password = RijndaelSimple.Decrypt(Table.Source_Pass, "passPhrase", "saltValue", "SHA1", 1, "initVector", 128);

            repo = Repository;

            this.Table             = Table;
            sourceConnectionString = "Provider=OraOLEDB.Oracle; Data Source=" + Table.Source_DB + ".world; User Id=" + Table.Source_User + "; Password="******";";

            tableName        = TableName;
            this.ExecutionId = ExecutionId;
        }
Exemple #10
0
        protected override byte[] LoadFilter(byte[] data)
        {
            if (_key == null || _key.Length == 0)
            {
                throw new CryptographicException("Key not set");
            }

            var aes = new RijndaelSimple(_key);

            data = aes.Decrypt(data, 256);
            return(base.LoadFilter(data));
        }
Exemple #11
0
            /// <summary>
            /// Decrypts a string
            /// </summary>
            /// <param name="text">String to be decrypted</param>
            /// <returns>Decrypted string</returns>
            public string Decrypt(string text)
            {
                try
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        return(RijndaelSimple.Decrypt(text, PassPhrase, Salt, "SHA1", 2, IV16Chars, 256));
                    }

                    return(text);
                }
                catch { return(text); }
            }
Exemple #12
0
        static void Main(string[] args)
        {
            LandingRepository repo = new LandingRepository();

            logger.Info("~~~~ Program Started ~~~~");

            List <Landing_Table> import_tables = repo.GetLandingTables();

            foreach (Landing_Table table in import_tables)
            {
                logger.Info("Importing {0}", table.Table_Name);
                Landing_Table_Log TableLog = repo.New_Log_Record(table.id);

                try
                {
                    String password = RijndaelSimple.Decrypt(table.Source_Pass, "PLanning and Audit", "Diplomatic Persistance", "SHA1", 1, "AGHYEFIVOPJNSFRU", 128);

                    if (repo.TableExists(table.Dest_Schema, table.Table_Name))
                    {
                        logger.Debug("Table {0}.{1} exists", table.Dest_Schema, table.Table_Name);
                    }
                    else
                    {
                        logger.Debug("Table {0}.{1} does not exist", table.Dest_Schema, table.Table_Name);
                    }


                    TableLog.Start_Time = DateTime.Now;
                    TableLog.Success    = 0;
                    repo.Update_Log(TableLog);
                } catch (Exception ex)
                {
                    TableLog.Notes = "Exception: " + ex.Message;
                    logger.Error(ex, "Error loading table " + table.Table_Name);
                } finally
                {
                    logger.Info("Finished {0}", table.Table_Name);
                    TableLog.End_Time = DateTime.Now;
                    repo.Update_Log(TableLog);
                }
            }


            logger.Info("~~~~ Program Finished ~~~~");


            //System.Console.ReadKey();
            LogManager.Flush();
            LogManager.Shutdown();
        }
Exemple #13
0
 /// <summary>
 /// Decrypt a byte array that was encrypted using the Rinjdael encryption algorithm.
 /// </summary>
 /// <param name="data">The encrypted data.</param>
 /// <param name="key">The key to decrypt with.</param>
 static public byte[] Decrypt(byte[] data, string key)
 {
     try
     {
         return RijndaelSimple.Decrypt(data,
                                        key,
                                        saltValue,
                                        hashAlgorithm,
                                        passwordIterations,
                                        initVector,
                                        keySize);
     }
     catch (Exception e)
     {
         throw new Exception("Rinjdael \"Decrypt()\": " + e.Message);
     }
 }
Exemple #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));
            }
        }
Exemple #15
0
        public float GetSurvivalTime()
        {
            if (!File.Exists(EngineConfig.C_SURVIVAL_FILE))
            {
                return(0);
            }

            string raw = File.ReadAllText(EngineConfig.C_SURVIVAL_FILE);

            try
            {
                return(float.Parse(RijndaelSimple.Decrypt(raw)));
            }
            catch (Exception)
            {
                return(0);
            }
        }
Exemple #16
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;
            }
        }
Exemple #17
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);
        }
Exemple #18
0
        public static MySqlConnection GetConnection()
        {
            //conn is an object of the "MySqlConnection" class. It will be returned to other C# classes
            // it can be referenced in other classes to provide a connection to the database where needed
            //For example, a function containing a query on the DB
            string connectionString;
            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
            string fileName           = "C:\\DBBackup\\stored.dat";
            String password           = RijndaelSimple.Decrypt(File.ReadAllText(fileName), passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);

            connectionString = "SERVER=localhost; DATABASE =dhrp; USERNAME=nomawkellner; Password=" + password;
            MySqlConnection conn = new MySqlConnection(connectionString);

            return(conn);
        }
        /// <summary>
        /// Wczytuje konfiguracje z podanego pliku.
        /// </summary>
        /// <param name="path">Sciezka do pliku zawierajacego konfiguracje lementow gry.</param>
        /// <param name="isCryptData">Czy dane sa zaszyfrowane.</param>
        public ReadConfiguration(string path, bool isCryptData)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentException(String.Format("Podana sciezka: {0} nie istnieje !", path), "path");
            }
            if (!File.Exists(path))
            {
                throw new ConfigurationFileNotFoundException(Path.GetFileName(path));
            }

            Init();
            if (isCryptData)
            {
                ReadFile(XmlTextReader.Create(new StringReader(RijndaelSimple.Decrypt(File.ReadAllText(path)))));
            }
            else
            {
                ReadFile(XmlReader.Create(new XmlTextReader(path), GetSettings()));
            }
        }
Exemple #20
0
        public static CompletedLevelsInfo GetCompletedLevels()
        {
            CompletedLevelsInfo completedLevels = new CompletedLevelsInfo();

            completedLevels.CompletedLevels = new SerializableDictionary <LevelInfo, List <Achievement> >();

            List <Achievement> emptyAchievements = new List <Achievement>();

            if (!File.Exists(EngineConfig.C_COMPLETED_LEVELS_FILE))
            {
                completedLevels = CompletedLevelsInfo.GetDefaultCompletedLevelsInfo();
                return(completedLevels);
            }
            else
            {
                try
                {
                    string levelsRaw    = File.ReadAllText(EngineConfig.C_COMPLETED_LEVELS_FILE);
                    string levelsString = RijndaelSimple.Decrypt(levelsRaw);

                    using (Stream stream = GenerateStreamFromString(levelsString))
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(CompletedLevelsInfo));
                        ;
                        var levels = ( CompletedLevelsInfo)serializer.Deserialize(stream);
                        return(levels as CompletedLevelsInfo);
                    }
                }
                catch (Exception ex)
                {
                    completedLevels.CompletedLevels.Clear();
                    completedLevels.CompletedLevels.Add(new LevelInfo(XmlLevelParser.GetLevelFileName(1), false), emptyAchievements);
                    Console.WriteLine(ex);
                }


                return(completedLevels);
            }
        }
Exemple #21
0
        internal List <String> Load(string fileName)
        {
            string fullPath = Methods.Instance.GetApplicationPath + fileName;

            if (File.Exists(fullPath))
            {
                string input;
                var    args = new List <String>();

                using (var tr = new StreamReader(fullPath)) {
                    while ((input = tr.ReadLine()) != null)
                    {
                        if (input != null)
                        {
                            args.Add(RijndaelSimple.Decrypt(input));
                        }
                    }
                }
                return(args);
            }
            return(null);
        }
Exemple #22
0
        protected void Decrypt(string trackLinkUri)
        {
            Uri = trackLinkUri;

            string[] parts = trackLinkUri.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length != 3)
            {
                throw new InvalidOperationException("Unable to parse link");
            }

            TrackSource = parts[1];

            string encrypted = parts[2];
            string decrypted = RijndaelSimple.Decrypt(encrypted, Passphrase, SaltValue, "SHA1", 1, InitVector, 256);

            var result = HttpUtility.ParseQueryString(decrypted);

            foreach (string key in result.AllKeys)
            {
                _builder.Add(key, result[key]);
            }
        }
Exemple #23
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);
        }
Exemple #24
0
        public async Task <VerifyExternalLoginWhenAccountIsExistModel> VerifyExternalLoginWhenAccountIsExist(VerifyExternalLoginWhenAccountIsExistModel model)
        {
            try
            {
                var page = await base.InitPage();

                model.SetInitInfo(page);
                RVerify verify = await _emailSmsService.GetVerifyFromDb(model.VerifyId);

                if (verify == null)
                {
                    model.AddMessage(ResourceKey.Verify_NotExist);
                    return(model);
                }
                if (verify.CheckStatus(EnumDefine.VerifyStatusEnum.Used))
                {
                    model.AddMessage(ResourceKey.Verify_Used);
                    return(model);
                }
                if (verify.CheckStatus(EnumDefine.VerifyStatusEnum.Cancel))
                {
                    model.AddMessage(ResourceKey.Verify_Cancel);
                    return(model);
                }
                if (verify.ExpireDate < Extensions.GetCurrentDateUtc())
                {
                    model.AddMessage(ResourceKey.Verify_Expired);
                    return(model);
                }
                RijndaelSimple rijndaelSimple = new RijndaelSimple();
                string         verifyCode;
                try
                {
                    string code = UnicodeUtility.FromHexString(model.VerifyCode);
                    verifyCode = rijndaelSimple.Decrypt(code, verify.SaltKey);
                }
                catch (Exception e)
                {
                    model.AddMessage(ResourceKey.Verify_CodeNotExact);
                    return(model);
                }
                if (verify.VerifyCode != verifyCode)
                {
                    model.AddMessage(ResourceKey.Verify_CodeNotExact);
                    return(model);
                }
                ActiveCodeWhenAccountIsExistModel activeCodeWhenAccountIsExistModel =
                    verify.GetModel <ActiveCodeWhenAccountIsExistModel>();
                var customer = await _customerService.GetFromDb(activeCodeWhenAccountIsExistModel.CustomerId);

                CustomerExternalLoginAddCommand command = new CustomerExternalLoginAddCommand()
                {
                    LoginProvider       = activeCodeWhenAccountIsExistModel.LoginProvider,
                    ProviderKey         = activeCodeWhenAccountIsExistModel.ProviderKey,
                    ProviderDisplayName = activeCodeWhenAccountIsExistModel.LoginProvider.ToString(),
                    CustomerId          = activeCodeWhenAccountIsExistModel.CustomerId,
                    Info     = activeCodeWhenAccountIsExistModel.Info,
                    VerifyId = verify.Id,
                    Version  = customer.Version
                };
                var result = await _customerService.SendCommand(command);

                if (!result.IsSucess)
                {
                    model.AddMessage(result.Message);
                }
                return(model);
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                throw e;
            }
        }
Exemple #25
0
 private static string DecryptLicense(string licenseContents)
 {
     return(RijndaelSimple.Decrypt(licenseContents, Hash, RijndaelSimple.saltValue,
                                   RijndaelSimple.hashAlgorithm, RijndaelSimple.passwordIterations,
                                   RijndaelSimple.initVector, RijndaelSimple.keySize));
 }
Exemple #26
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();
        }
Exemple #27
0
        public static void Main(string[] args)
        {
            try
            {
                int userInput = 0;
                if (args.Any())
                {
                    var cmdOptions = Parser.Default.ParseArguments <ProgramOptions>(args);
                    cmdOptions.WithParsed(
                        options => {
                        HandleCommandLine(options);
                    });
                    Console.ReadLine();
                }
                else
                {
                    do
                    {
                        userInput = DisplayMenu();
                        switch (userInput)
                        {
                        case 1:
                            TestUsernameAndPassword(string.Empty, string.Empty);
                            break;

                        case 2:
                            Console.WriteLine("Would you like to run chrome in headless mode Y/N?");
                            if (Console.ReadLine().ToLower() == "y")
                            {
                                RiverLinkLogic.runHeadless = true;
                            }
                            if (Properties.Settings.Default.Username != "" || Properties.Settings.Default.Password != "")
                            {
                                var spinner = new Spinner(10, 10);
                                spinner.Start();

                                driver = RiverLinkLogic.GetNewDriver();
                                RiverLinkLogic Logic = new RiverLinkLogic("https://riverlink.com/", 2000, 1000, driver);
                                Logic.Login(RijndaelSimple.Decrypt <RijndaelManaged>(Properties.Settings.Default.Username, "username", "salt"), RijndaelSimple.Decrypt <RijndaelManaged>(Properties.Settings.Default.Password, "password", "salt"));
                                Logic.GetData();

                                spinner.Stop();
                            }
                            else
                            {
                                Console.WriteLine("Please run option 1 to set and test your username and password first.");
                            }
                            break;

                        case 3:
                            RiverLinkLogic Insert = new RiverLinkLogic("https://riverlink.com/", 2000, 1000, driver);
                            Insert.InsertData();
                            break;

                        case 4:
                            Application.Exit();
                            break;
                        }
                    } while (userInput != 4);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"{methodName} unexpected error: {e}");
                throw new Exception($"{methodName} unexpected error: {e}");
            }
        }