Esempio n. 1
0
        public string OpenConnection(string usernName, string password)
        {
            string   sConnection = "";
            Rijndael oRijndael;

            oRijndael = new Rijndael();
            string oUserName = oRijndael.Decrypt(usernName);
            string oUserPwd  = oRijndael.Decrypt(password);

            sConnection = oConnectionManager.OpenUserConnect(oUserName, oUserPwd);
            return(sConnection);
        }
Esempio n. 2
0
        public async Task <ActionResult> ResetPassword(User model)
        {
            try
            {
                model.Email = Rijndael.Decrypt(model.Email.Replace('-', '+').Replace('_', '/'));

                User _user = await db.Users.FirstOrDefaultAsync(c => c.Email == model.Email && c.IsDataActive);

                if (_user != null)
                {
                    byte[] _authString = AppManager.GetAuthstring(model.Email, model.Password);

                    _user.AuthString    = _authString;
                    _user.LastUpdatedOn = AppManager.Now;

                    await db.SaveChangesAsync();

                    TempData["Notification"] = new Notification("Success", "Password has been changed successfully.");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    TempData["Notification"] = new Notification("Error", "Sorry, we are unable to process your request. Please try again later.");
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
                TempData["Notification"] = new Notification("Error", "Sorry, we are unable to process your request. Please try again later.");
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 3
0
        private void bGo_Click(object sender, EventArgs e)
        {
            try
            {
                //Make sure that we have a value
                if (string.IsNullOrWhiteSpace(tSourceString.Text))
                {
                    throw new ApplicationException("No source string provided.");
                }

                Rijndael rijndael = new Rijndael(_key, _iv);

                string input = tSourceString.Text.Trim();

                string output;
                if (rbEncrypt.Checked)
                {
                    output = rijndael.Encrypt(input);
                }
                else
                {
                    output = rijndael.Decrypt(tSourceString.Text);
                }

                tOutputString.Text = output;
            }
            catch (Exception ex)
            {
                DisplayError(ex.Message);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Decrypt the incoming password using the Rijndael algorithm.
        /// </summary>
        /// <param name="passwordData">Password as byte array</param>
        /// <returns></returns>
        private string DecryptPassword(byte[] passwordData)
        {
            var encryptionKey = this.Server.LoginConfiguration.EncryptionKey;
            var key           = Encoding.ASCII.GetBytes(encryptionKey).Concat(Enumerable.Repeat((byte)0, 5).ToArray()).ToArray();

            return(Rijndael.Decrypt(passwordData, key).Trim('\0'));
        }
Esempio n. 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            string key       = keyBox.Text.PadRight(16, ' ');
            int    numBlocks = ciphertextBox.Text.Length / 16 + 1;

            plaintextBox.Text = Rijndael.Decrypt(ciphertextBox.Text.PadRight(16 * numBlocks, '\0'), key);
        }
Esempio n. 6
0
        /// <summary>
        /// Constructor which takes the connection string name
        /// </summary>
        /// <param name="connectionStringName"></param>
        public OracleDatabase(string connectionString)
        {
            Rijndael            oRijndael           = new Rijndael();
            ResourceFileManager resourceFileManager = null;

            resourceFileManager = ResourceFileManager.Instance;
            resourceFileManager.SetResources();
            if (resourceFileManager.getConfigData("isTest") == "SI")
            {
                _connection = new OracleConnection(oRijndael.Decrypt(resourceFileManager.getConfigData(connectionString)));
            }
            else
            {
                _connection = new OracleConnection(oRijndael.Decrypt(resourceFileManager.getConfigData("ConnectionStringProd")));
            }
        }
Esempio n. 7
0
 public static Guid?DecryptNullableId(string id)
 {
     if (string.IsNullOrWhiteSpace(id))
     {
         return(null);
     }
     return(Guid.ParseExact(Rijndael.Decrypt(id, SADFM.Base.Constants.IdKey), "N"));
 }
Esempio n. 8
0
    /// <summary>
    /// 解密
    /// </summary>
    /// <param name="KeyPath"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    public byte[] DecryptVideo(string KeyPath, byte[] data)
    {
        Rijndael rij = new Rijndael();

        RijndaelKey rijKey = rij.GetKeyAndIV(KeyPath);

        return(rij.Decrypt(data, rijKey.key, rijKey.IV));
    }
Esempio n. 9
0
    //---------------------------------------------------------------
    public void LoadData()
    {
        byte[] soupBackIn   = File.ReadAllBytes(filename);
        string jsonFromFile = crypto.Decrypt(soupBackIn, JSON_ENCRYPTED_KEY);

        SaveData copy = JsonUtility.FromJson <SaveData>(jsonFromFile);

        Debug.Log(copy.health);
    }
Esempio n. 10
0
        public void RandomIv256()
        {
            var ciphertext1 = Rijndael.Encrypt(Plaintext, Password, KeySize.Aes256);
            var ciphertext2 = Rijndael.Encrypt(Plaintext, Password, KeySize.Aes256);
            var plaintext   = Rijndael.Decrypt(ciphertext1, Password, KeySize.Aes256);

            Assert.Equal(plaintext, Plaintext);
            Assert.NotEqual(ciphertext1, ciphertext2);
        }
        public async Task <ActionResult> Dashboard()
        {
            var _response = await Client.GetAddressBalancesAsync(Rijndael.Decrypt(AppManager.User.BCHash));

            ViewBag.Response           = _response.Result;
            ViewBag.RecentTransactions = (await Client.ListAddressTransactionsAsync(Rijndael.Decrypt(AppManager.User.BCHash), 100)).Result.Where(i => i.balance.assets != null).OrderByDescending(i => i.time).Take(10).ToList();
            ViewBag.Requests           = await db.Requests.Include(r => r.User).Where(r => r.IsDataActive && r.SenderID == AppManager.User.ID || r.Recipient == AppManager.User.Email || r.Recipient == AppManager.User.NickName).OrderByDescending(r => r.ID).Take(10).ToListAsync();

            return(View(await db.Users.FirstOrDefaultAsync(u => u.ID == AppManager.User.ID)));
        }
Esempio n. 12
0
        public async Task <ActionResult> Send()
        {
            ViewBag.Asset = (await Client.GetAddressBalancesAsync(Rijndael.Decrypt(AppManager.User.BCHash))).Result.Select(i => new SelectListItem
            {
                Text  = $"{i.Name} ({i.Qty} available in wallet)",
                Value = i.AssetRef
            });

            return(View());
        }
Esempio n. 13
0
        public static XmlNode DecryptNode(XmlNode encryptedNode)
        {
            string decryptedData = Rijndael.Decrypt(encryptedNode.InnerText, key, KeySize.Aes256);

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml(decryptedData);

            return(xmlDoc.DocumentElement);
        }
Esempio n. 14
0
        public string Decrypt(string text)
        {
            string textPlan = "";

            if (text != null)
            {
                textPlan = Rijndael.Decrypt(text, _password, KeySize.Aes256);
            }

            return(textPlan);
        }
        public async Task <ActionResult> Issue(Asset model)
        {
            if (ModelState.IsValid)
            {
                var _recipient = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Address && u.IsDataActive);

                if (_recipient != null && !string.IsNullOrEmpty(_recipient.BCHash))
                {
                    if (!string.IsNullOrEmpty(Request.QueryString["asset_name"]))
                    {
                        var _duplicateAssets = (await Client.ListAssetsAsync(model.Name)).Result;
                        var _response        = await Client.IssueMoreAsync(Rijndael.Decrypt(_recipient.BCHash), model.Name, model.Quantity);

                        if (string.IsNullOrEmpty(_response.Error))
                        {
                            TempData["Notification"] = new Notification("Success", $"More quantity of {model.Name} has been issued successfully");
                        }
                        else
                        {
                            TempData["Notification"] = new Notification("Error", _response.Error);
                        }
                    }
                    else
                    {
                        object _asset = new
                        {
                            name = model.Name,
                            open = true
                        };

                        var _response = await Client.IssueAsync(Rijndael.Decrypt(_recipient.BCHash), _asset, model.Quantity, model.Units);

                        if (string.IsNullOrEmpty(_response.Error))
                        {
                            TempData["Notification"] = new Notification("Success", "New Asset has been created successfully");
                        }
                        else
                        {
                            TempData["Notification"] = new Notification("Error", _response.Error);
                        }
                    }
                }
                else
                {
                    TempData["Notification"] = new Notification("Error", "Invalid Recipient. Please try again later.");
                }
            }
            else
            {
                TempData["Notification"] = new Notification("Error", "One or more required fields are missing. Please try again later.");
            }

            return(Redirect("/Assets/Index"));
        }
        /// <summary>
        /// Recebe um texto criptografado e retorna uma string em texto plano.
        /// </summary>
        /// <param name="textoCriptografado"></param>
        /// <returns></returns>
        public static string Descriptografar(string textoCriptografado)
        {
            string textoPlano = "";

            if (textoCriptografado != null)
            {
                textoPlano = Rijndael.Decrypt(textoCriptografado, password, KeySize.Aes256);
            }

            return(textoPlano);
        }
Esempio n. 17
0
        /// <summary>
        /// Receives an encrypted text and returns a plain text string
        /// </summary>
        /// <param name="textEncrypted"></param>
        /// <returns></returns>
        public static string Decrypt(string textEncrypted)
        {
            string textPlan = "";

            if (textEncrypted != null)
            {
                textPlan = Rijndael.Decrypt(textEncrypted, password, KeySize.Aes256);
            }

            return(textPlan);
        }
Esempio n. 18
0
 public void Desencriptar()
 {
     this._pgsqlhost       = _rij.Decrypt(this._pgsqlhost);
     this._pgsqlport       = _rij.Decrypt(this._pgsqlport);
     this._pgsqldb         = _rij.Decrypt(this._pgsqldb);
     this._pgsqlusr        = _rij.Decrypt(this._pgsqlusr);
     this._pgsqlpwd        = _rij.Decrypt(this._pgsqlpwd);
     this._pgsqlCmdTimeOut = _rij.Decrypt(this._pgsqlCmdTimeOut);
     this._perfil          = _rij.Decrypt(this._perfil);
 }
Esempio n. 19
0
    public void dataload()
    {
        Rijndael crypto   = new Rijndael();
        string   filename = Path.Combine(Application.persistentDataPath, SAVE_FILE);

        byte[]   soupBackIn   = File.ReadAllBytes(filename);
        string   jsonFromFile = crypto.Decrypt(soupBackIn, JSON_ENCRYPTED_KEY);
        SaveData copy         = JsonUtility.FromJson <SaveData>(jsonFromFile);

        scorevalue = copy.scorevalue;
        Debug.Log(copy.scorevalue);
    }
        public async Task <ActionResult> Signup(User model)
        {
            model.ConfirmPassword = model.Password;

            ModelState.Clear();
            TryValidateModel(model);

            if (ModelState.IsValid)
            {
                if (!await db.Users.AnyAsync(u => (u.Email == model.Email || u.Username.ToLower() == model.Username.ToLower()) && u.IsDataActive))
                {
                    try
                    {
                        model.AuthString   = Rijndael.Encrypt(string.Concat(model.Username.ToLower(), model.Password));
                        model.CreatedOn    = model.LastUpdatedOn = DateTime.Now;
                        model.Username     = model.Username.ToLower();
                        model.IsDataActive = true;
                        model.IsSearchable = false;

                        db.Users.Add(model);
                        await db.SaveChangesAsync();

                        model.BCHash = await AppManager.CreateAddress();

                        await db.SaveChangesAsync();

                        await Client.IssueMoreAsync(Rijndael.Decrypt(model.BCHash), "Seratio Coin", 1000);

                        string _body = $"Hello {(model.NickName != null ? model.NickName : "@" + model.Username.ToLower())} ,<br /><br />Welcome to Seratio Blockchain.<br />We have added 1000 Seratio Coins to your wallet for you to get started with our Platform.";
                        AppManager.SendEmail("Welcome to Seratio Blockchain", model.Email, _body);

                        TempData["Notification"] = new Notification("Success", "Welcome to Seratio Blockchain, your account has been created successfully.");
                        return(RedirectToAction("index"));
                    }
                    catch (DbEntityValidationException ex)
                    {
                        string _errorMessages = string.Join("; ", ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage));
                        TempData["Notification"] = new Notification("Error", _errorMessages);
                    }
                }
                else
                {
                    TempData["Notification"] = new Notification("Error", "There is an existing account associated with this email or Username.");
                }
            }
            else
            {
                TempData["Notification"] = new Notification("Error", "One or more required fields are missing. Please try again later.");
            }

            return(View(model));
        }
Esempio n. 21
0
 public IVersion GetLocalVersion()
 {
     if (FilesManager.Exists(Settings.GetVersionFilePath()))
     {
         var encryptedVersion = File.ReadAllText(Settings.GetVersionFilePath());
         var decryptedVersion = Rijndael.Decrypt(encryptedVersion, Settings.EncryptionKeyphrase);
         return(Serializer.Deserialize <IVersion>(decryptedVersion));
     }
     else
     {
         return(null);
     }
 }
Esempio n. 22
0
 private ZPrincipal GetPrincipal(HttpActionContext actionContext)
 {
     try
     {
         string authHeader = actionContext.Request.Headers.GetValues(AuthConfiguration.AuthHeader).First();
         var    result     = Rijndael.Decrypt(authHeader, Rijndael.GetRandomKeyText());
         return(JsonConvert.DeserializeObject <ZPrincipal>(result));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 23
0
    public static async Task <ProfileData> LoadProfileAsync(string path, string profileName, string profileId)
    {
        // This is the encrypted input from the file
        byte[] soupBackIn = await AsyncHelperExtensions.ReadBytesAsync(path);

        // Creates the unique Encryption key per profile
        string jsonEncryptedKey = $"{profileName}BXRB98y-h^4^.ct^]~8|Cmn5([]+/+{profileName}@&";

        // If the key is shorter then 32 characters it will make it longer
        if (jsonEncryptedKey.Length < 33)
        {
            while (jsonEncryptedKey.Length < 33)
            {
                jsonEncryptedKey = $"{profileName}BXRB98y-h^4^.ct^]~8|Cmn5([-+/{profileName}@&{profileName}";
            }
        }
        // If the value is longer then 32 characters it will make it 32 characters
        if (jsonEncryptedKey.Length > 32)
        {
            jsonEncryptedKey = jsonEncryptedKey.Truncate(32);
        }

        // Decrypting process
        Rijndael crypto       = new Rijndael();
        string   jsonFromFile = crypto.Decrypt(soupBackIn, jsonEncryptedKey);

        // Creates a ProfileData object with the information from the json file
        ProfileData profile = JsonUtility.FromJson <ProfileData>(jsonFromFile);

        // Checks if the decrypted Profile Data is null or not
        if (profile == null)
        {
            Debug.Log("Failed to load profile");
            return(null);
        }
        if (profile.fullProfileName != profileName)
        {
            Debug.Log("Profile Name's are not matching");
            return(null);
        }
        if (profile.profileId != profileId)
        {
            Debug.Log("Profile ID's are not matching");
            return(null);
        }

        SaveManagerEvents.current.ProfileLoaded(profile);

        return(profile);
    }
Esempio n. 24
0
    public static async Task LoadAllProfilesAsync(string path)
    {
        // This is the encrypted input from the file
        byte[] soupBackIn = await AsyncHelperExtensions.ReadBytesAsync(path);

        // Decrypting process
        Rijndael crypto       = new Rijndael();
        string   jsonFromFile = crypto.Decrypt(soupBackIn, JsonEncryptedKeyProfiles);

        ProfilesListWrapper profiles = JsonUtility.FromJson <ProfilesListWrapper>(jsonFromFile);

        SaveManager.profiles = profiles == null ? new List <ProfilesData>() : profiles.Profiles;

        SaveManagerEvents.current.AllProfilesLoaded(SaveManager.profiles);
    }
Esempio n. 25
0
 private void SetCurrentVersion()
 {
     if (FilesManager.Exists(Settings.GetVersionFilePath()))
     {
         var encryptedVersion = File.ReadAllText(Settings.GetVersionFilePath());
         var decryptedVersion = Rijndael.Decrypt(encryptedVersion, Settings.EncryptionKeyphrase);
         CurrentVersion = Serializer.Deserialize <IVersion>(decryptedVersion);
         Logger.Info("Retrieved current version: {CurrentVersion}", CurrentVersion);
     }
     else
     {
         CurrentVersion = null;
         Logger.Warning("No current version found. A full repair may be required.");
     }
 }
Esempio n. 26
0
    // Use this for initialization
    void Start()
    {
        byte[] bytes = new byte[4] {
            100, 99, 98, 97
        };
        RijndaelManaged rijma = new RijndaelManaged();

        rijma.GenerateKey();
        rijma.GenerateIV();
        Rijndael rij = new Rijndael();

        byte[] enbytes = rij.Encrypt(bytes, rijma.Key, rijma.IV);


        byte[] debytes = rij.Decrypt(enbytes, rijma.Key, rijma.IV);
    }
Esempio n. 27
0
        public bool ValidateApplicationToken(string appId, string appToken)
        {
            if (string.IsNullOrWhiteSpace(appId) || string.IsNullOrWhiteSpace(appToken))
            {
                return(false);
            }

            var appAuth = _applicationAuthenticationRepository.GetByAppIdAndTokenId(Rijndael.Decrypt(appId), Rijndael.Decrypt(appToken));

            if (appAuth != null)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 28
0
        public static object openPackage(byte[] package)
        {
            package = Rijndael.Decrypt(package);

            byte[] packetdata;

            if (package[0] != 255 || package[package.Length - 1] != 255)
            {
                throw new NotImplementedException();
            }

            packetdata = trimMessage(package);

            switch (package[1])
            {
            case (byte)DATATYPE.INT:
                byte tmp = packetdata[0];
                return(Convert.ToInt32(tmp));

            case (byte)DATATYPE.DOUBLE:
                tmp = packetdata[0];
                return(Convert.ToDouble(tmp));

            case (byte)DATATYPE.STRING:
                return(Encoding.ASCII.GetString(packetdata));

            case (byte)DATATYPE.CPU:
                return(JsonConvert.DeserializeObject <CPU>(Encoding.ASCII.GetString(packetdata)));

            case (byte)DATATYPE.OS:
                return(JsonConvert.DeserializeObject <OS>(Encoding.ASCII.GetString(packetdata)));

            case (byte)DATATYPE.DISK:
                return(JsonConvert.DeserializeObject <Disk>(Encoding.ASCII.GetString(packetdata)));

            case (byte)DATATYPE.NETWORK:
                throw new NotImplementedException();

            //ToDo: NotImplemented
            case (byte)DATATYPE.RAM:
                return(JsonConvert.DeserializeObject <RAM>(Encoding.ASCII.GetString(packetdata)));

            case (byte)DATATYPE.MAINBOARD:
                return(JsonConvert.DeserializeObject <Mainboard>(Encoding.ASCII.GetString(packetdata)));
            }
            return(null);
        }
Esempio n. 29
0
        private void AssignConnectionString()
        {
            //Attempt to retrieve the connection string from the web.config file
            ConnectionStringSettings connStrSettings;

            if ((connStrSettings = ConfigurationManager.ConnectionStrings["MsSqlRepository"]) == null)
            {
                throw new ConnectionStringAssignmentException();
            }

            //We expect the connection string to be encrypted, so decrypt it
            string encryptedConnStr = connStrSettings.ConnectionString;

            Rijndael rijndael = new Rijndael(_key, _iv);

            _connectionString = rijndael.Decrypt(encryptedConnStr);
        }
Esempio n. 30
0
    // Load Game
    public static async Task <GameData> LoadGameAsync()
    {
        if (SelectedProfileManager.selectedProfile == null)
        {
            return(null);
        }

        string fullProfileName = SelectedProfileManager.selectedProfile.fullProfileName;

        string path = Path.Combine(MainDirectoryPath, fullProfileName, "Save", "data.dat");

        if (!File.Exists(path))
        {
            return(null);
        }

        // This is the encrypted input from the file
        byte[] soupBackIn = await AsyncHelperExtensions.ReadBytesAsync(path);

        // Creates the unique Encryption key per profile
        string jsonEncryptedKey = "|9{Ajia:p,g<ae&)9KsLy7;<t9G5sJ>G";

        // If the value is longer then 32 characters it will make it 32 characters
        if (jsonEncryptedKey.Length > 32)
        {
            jsonEncryptedKey = jsonEncryptedKey.Truncate(32);
        }

        // Decrypting process
        Rijndael crypto       = new Rijndael();
        string   jsonFromFile = crypto.Decrypt(soupBackIn, jsonEncryptedKey);

        // Creates a ProfileData object with the information from the json file
        GameData gameData = JsonUtility.FromJson <GameData>(jsonFromFile);

        // Checks if the decrypted Profile Data is null or not
        if (gameData == null)
        {
            Debug.Log("Failed to load game data.");
            return(null);
        }

        SaveManagerEvents.current.LoadGame(gameData, SelectedProfileManager.selectedProfile);

        return(gameData);
    }
Esempio n. 31
0
        private static void CryptoTest()
        {
            var serializer = new BinaryFormatter(Encoding.Unicode);
            var tripleDes = new Rijndael();

            var model = GenerateRelatedModel();
            var bytes = serializer.Serialize(model);
            var enc = tripleDes.Encrypt(bytes);
            var dec = tripleDes.Decrypt(enc);
            var des = serializer.Deserialize(dec);

            var enc2 = tripleDes.Encrypt(bytes);
            var dec2 = tripleDes.Decrypt(enc2);
        }
Esempio n. 32
0
 public string Decode(byte[] bytesToDecode)
 {
     Rijndael decoder = new Rijndael(Key);
     return decoder.Decrypt(bytesToDecode);
 }