Esempio n. 1
0
    public void SaveInfo()
    {
        string format = "d/M/yyyy HH:mm:ss";
        Dictionary <string, object> dict = new Dictionary <string, object> ();

        dict.Add("carrots", UserInfo.UserI.carrots);
        dict.Add("exp", UserInfo.UserI.exp);
        dict.Add("missionsComplete", UserInfo.UserI.missionsComplete);
        dict.Add("fuelGame", UserInfo.UserI.fuelGame);
        dict.Add("LastFuelTimer", UserInfo.UserI.LastFuelTimer.ToString(format));
        dict.Add("objects", UserInfo.UserI.objects);

        string json = Json.Serialize(dict);

        Debug.Log(json);
        Rijndael crypto = new Rijndael();

        byte[] soup = crypto.Encrypt(json, JSON_ENCRYPTED_KEY);

        string filename = Path.Combine(Application.persistentDataPath, SAVE_FILE);

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

        File.WriteAllBytes(filename, soup);

        Debug.Log("Datos guardados");
    }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            string key       = keyBox.Text.PadRight(16, ' ');
            int    numBlocks = plaintextBox.Text.Length / 16 + 1;

            ciphertextBox.Text = Rijndael.Encrypt(plaintextBox.Text.PadRight(16 * numBlocks, '\0'), key);
        }
Esempio n. 3
0
        private void BuildVersionFile()
        {
            var encoded   = _context.Serializer.Serialize(_context.BuildVersion);
            var encrypted = Rijndael.Encrypt(encoded, _context.Settings.EncryptionKeyphrase);

            File.WriteAllText(_context.Settings.GetVersionFilePath(_context.BuildVersion), encrypted);
        }
Esempio n. 4
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. 5
0
        public static Func <string, string, Task <IUserMessage> > SendMessageToChannel(IMessageChannel channel, bool replyable, ShardedCommandContext context, bool forceEmbed = false)
        {
            if (!replyable)
            {
                return(async(username, message) =>
                {
                    message = CheckForMentions(channel, message);
                    if (forceEmbed)
                    {
                        var view = Views.Message.Response(username, message, null);
                        return await SendMessageAndCatchError(() => { return channel.SendMessageAsync(view.Item1, embed: view.Item2); }, context);
                    }

                    if (string.IsNullOrEmpty(username))
                    {
                        return await SendMessageAndCatchError(() => { return channel.SendMessageAsync(message); }, context);
                    }
                    return await SendMessageAndCatchError(() => { return channel.SendMessageAsync($"**{username}**: {message}"); }, context);
                });
            }
            return(async(username, message) =>
            {
                var key = LoadConfig.Instance.config["encryptionKey"];
                var replyHash = Rijndael.Encrypt(context.User.Id.ToString(), key, KeySize.Aes256);
                var view = Views.Message.Response(username, message, replyHash.ToString());
                return await SendMessageAndCatchError(() => { return channel.SendMessageAsync(view.Item1, embed: view.Item2); }, context);
            });
        }
Esempio n. 6
0
        public void Encrypt256()
        {
            var plaintext  = Encoding.UTF8.GetBytes(Plaintext);
            var ciphertext = Rijndael.Encrypt(plaintext, Password, Iv, KeySize.Aes256);

            Assert.Equal(Convert.ToBase64String(ciphertext), Proof256);
        }
Esempio n. 7
0
    // Save Options/Settings
    public static async Task SaveOptionsAsync(GameSettings gameSettings)
    {
        if (SelectedProfileManager.selectedProfile == null)
        {
            return;
        }

        string fullProfileName = SelectedProfileManager.selectedProfile.fullProfileName;

        if (gameSettings == null)
        {
            return;
        }

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

        string json = JsonUtility.ToJson(gameSettings);

        // Creates the unique Encryption key per profile
        string jsonEncryptedKey = "AhExy6ntHa>zkh+r@M;b^jM|=D=~!S{c";

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

        // Encryption process
        Rijndael crypto = new Rijndael();

        byte[] soup = crypto.Encrypt(json, jsonEncryptedKey);
        await AsyncHelperExtensions.WriteBytesAsync(path, soup);

        SaveManagerEvents.current.SaveOptions(gameSettings, SelectedProfileManager.selectedProfile);
    }
Esempio n. 8
0
    static void EncryptVideo(MenuCommand cmd)
    {
        //获取选择文件夹的路径
        string[] str     = Selection.assetGUIDs;
        string   path    = AssetDatabase.GUIDToAssetPath(str[0]);
        string   newPath = Application.dataPath + "/StreamingAssets/videoNew";

        FileTools.CreateDirectory(newPath);

        //获取指定路径下的指定类型资源
        DirectoryInfo root = new DirectoryInfo(path);

        FileInfo[]  files  = root.GetFiles("*.mp4");
        Rijndael    rij    = new Rijndael();
        RijndaelKey rijKey = rij.CreateKeyAndIV(newPath);

        for (int i = 0; i < files.Length; i++)
        {
            byte[] enBytes = rij.Encrypt(FileTools.ReadFile(files[i].FullName), rijKey.key, rijKey.IV);

            string strWriteFile = newPath + "/" + files[i].Name;
            FileTools.CreateFile(strWriteFile, enBytes);

            EditorUtility.DisplayProgressBar("进度", i + "/" + files.Length + "完成修改值", (float)i / files.Length);
        }
        EditorUtility.ClearProgressBar();
        AssetDatabase.Refresh();
    }
Esempio n. 9
0
 public static string EncryptId(Guid?id)
 {
     if (!id.HasValue)
     {
         return(null);
     }
     return(Rijndael.Encrypt(id.Value.ToString("N"), SADFM.Base.Constants.IdKey));
 }
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 static async Task <string> CreateAddress()
        {
            JsonRpcResponse <string> _response = await Client.GetNewAddressAsync();

            await Client.GrantAsync(new string[] { _response.Result }, BlockchainPermissions.Send);

            await Client.GrantAsync(new string[] { _response.Result }, BlockchainPermissions.Receive);

            return(Rijndael.Encrypt(_response.Result));
        }
Esempio n. 12
0
        /// <summary>
        /// Encrypts a node.
        /// </summary>
        /// <param name="node">An unencrypted node</param>
        /// <returns>An encrypted node</returns>
        private String encryptNode(string node)
        {
            // TODO: Not put the key in plaintext here. (It's just for local use right now anyway.)
            String encryptedNode;
            String key = "5Xx7ghbgpcAIQubJh9VOxzsexMK59z";

            encryptedNode = "  <EncryptedData>" + Rijndael.Encrypt(node, key, KeySize.Aes256) + "</EncryptedData>";

            return(encryptedNode);
        }
Esempio n. 13
0
        public static XmlNode EncryptNode(XmlNode node)
        {
            string encryptedData = Rijndael.Encrypt(node.OuterXml, key, KeySize.Aes256);

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.PreserveWhitespace = true;
            xmlDoc.LoadXml("<EncryptedData>" +
                           encryptedData + "</EncryptedData>");

            return(xmlDoc.DocumentElement);
        }
Esempio n. 14
0
 private void Encriptar()
 {
     this._pgsqlhost       = _rij.Encrypt(this._pgsqlhost);
     this._pgsqlport       = _rij.Encrypt(this._pgsqlport);
     this._pgsqldb         = _rij.Encrypt(this._pgsqldb);
     this._pgsqlusr        = _rij.Encrypt(this._pgsqlusr);
     this._pgsqlpwd        = _rij.Encrypt(this._pgsqlpwd);
     this._pgsqlCmdTimeOut = _rij.Encrypt(this._pgsqlCmdTimeOut);
     this._perfil          = _rij.Encrypt(this._perfil);
 }
        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. 16
0
        public string Get(string url, string login, string password, string domain = "")
        {
            var principal = new ZPrincipal
            {
                Url      = url,
                Login    = login,
                Domain   = domain,
                Password = password
            };

            var value  = JsonConvert.SerializeObject(principal);
            var result = Rijndael.Encrypt(value);

            return(result);
        }
Esempio n. 17
0
    public static void Save <T>(T data, string nameOfTheFile) where T : class
    {
        string json = JsonUtility.ToJson(data);

        byte[] soup = Rijndael.Encrypt(json, JSON_ENCRYPTED_KEY);

        string fileName = Path.Combine(Application.persistentDataPath, nameOfTheFile);

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

        File.WriteAllBytes(fileName, soup);
        Debug.Log(Application.persistentDataPath);
    }
Esempio n. 18
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. 19
0
    //---------------------------------------------------------------
    public void SaveData()
    {
        string json = JsonUtility.ToJson(data);

        crypto = new Rijndael();
        byte[] soup = crypto.Encrypt(json, JSON_ENCRYPTED_KEY);



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

        File.WriteAllBytes(filename, soup);
    }
        public static LoggedInUser AuthenticateUser(string Email, string Password)
        {
            try
            {
                string _authString = Rijndael.Encrypt(string.Concat(Email, Password));

                var _user = (from u in db.Users
                             where (u.Username.Equals(Email) || u.Email.Equals(Email)) && (u.AuthString.Equals(_authString)) && u.IsDataActive
                             select new
                {
                    u.NickName,
                    u.Phone,
                    u.ID,
                    u.Email,
                    u.BCHash,
                    u.Gender,
                    u.IsSuperAdmin,
                    u.Username,
                    u.IsSearchable,
                }).FirstOrDefault();

                if (_user != null)
                {
                    return(new LoggedInUser
                    {
                        NickName = _user.NickName,
                        ID = _user.ID,
                        Gender = _user.Gender,
                        Email = _user.Email,
                        BCHash = _user.BCHash,
                        Phone = _user.Phone,
                        Username = _user.Username,
                        IsSuperAdmin = _user.IsSuperAdmin,
                        IsSearchable = _user.IsSearchable,
                    });
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler.Handle(ex);
                return(null);
            }
        }
        public static string GetNameByBCHash(string address)
        {
            if (address == "17XoaF4NcEyYWEkYeS8LQnTwBRZgBz587MFGXu")
            {
                return("Seratio Platform");
            }

            string _hash = Rijndael.Encrypt(address);

            var _user = db.Users.FirstOrDefault(u => u.BCHash == _hash);

            if (_user != null)
            {
                return(string.IsNullOrEmpty(_user.NickName) ? "@" + _user.Username : _user.NickName);
            }

            return(address);
        }
Esempio n. 22
0
        public async Task <ActionResult> Forgot(string email)
        {
            User _user = await db.Users.FirstOrDefaultAsync(c => c.Email == email && c.IsDataActive && c.EmailVerifiedOn != null);

            if (_user != null)
            {
                string _hash = Rijndael.Encrypt(email);
                //  string _hash = Convert.ToBase64String(Encoding.UTF8.GetBytes(email));
                string _body = $"Hello,<br />You or someone else has requested to change the password for your Seratio Platform account.<br />Please <a href='{AppManager.AppURL}/users/default/resetpassword?email={_hash.Replace('+', '-').Replace('/', '_')}'>click here</a> to reset your password.<br /><br />You can ignore this message if you haven't requested to change the password.<br/><br/>Regards,<br/>CCEG<br/>";
                AppManager.SendEmail("Your Account Password - Seratio Platform", email, _body);

                TempData["Notification"] = new Notification("Success", "Please check your Email to Reset the Password.");
                return(RedirectToAction("Index"));
            }

            TempData["Notification"] = new Notification("Error", "Please check your Email ID.");
            return(RedirectToAction("Index"));
        }
Esempio n. 23
0
    public static async Task SaveAllProfilesAsync(string path)
    {
        ProfilesListWrapper profiles = new ProfilesListWrapper()
        {
            Profiles = SaveManager.profiles
        };

        string json = JsonUtility.ToJson(profiles);

        // Encrypting process
        Rijndael crypto = new Rijndael();

        byte[] soup = crypto.Encrypt(json, JsonEncryptedKeyProfiles);

        await AsyncHelperExtensions.WriteBytesAsync(path, soup);

        SaveManagerEvents.current.AllProfilesSaved(SaveManager.profiles);
    }
Esempio n. 24
0
    // Save all profiles to profiles.dat
    public static void SaveAllProfiles(string path)
    {
        ProfilesListWrapper profiles = new ProfilesListWrapper()
        {
            Profiles = SaveManager.profiles
        };

        string json = JsonUtility.ToJson(profiles);

        // Encrypting process
        Rijndael crypto = new Rijndael();

        byte[] soup = crypto.Encrypt(json, JsonEncryptedKeyProfiles);

        File.WriteAllBytes(path, soup);

        SaveManagerEvents.current.AllProfilesSaved(SaveManager.profiles);
    }
Esempio n. 25
0
    public static async Task SaveProfileAsync(string path, string profileImage, string profileName, string profileId, string fullProfileName)
    {
        ProfileData profile = CreateProfile(profileId, profileImage, profileName, fullProfileName, false);

        if (profile == null)
        {
            return;
        }

        string json = JsonUtility.ToJson(profile);

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

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

        // Encryption process
        Rijndael crypto = new Rijndael();

        byte[] soup = crypto.Encrypt(json, jsonEncryptedKey);
        await AsyncHelperExtensions.WriteBytesAsync(path, soup);

        ProfilesData profiles = CreateProfilesData(profileId, profileName, fullProfileName);

        await LoadAllProfilesAsync(ProfilesPath);

        SaveManager.profiles.Add(profiles);

        await SaveAllProfilesAsync(ProfilesPath);

        SaveManagerEvents.current.ProfileSaved(profile);
    }
Esempio n. 26
0
        public string Encrypt(string stringToEncrypt)
        {
            return(Rijndael.Encrypt(stringToEncrypt));
            //byte[] toEncryptArray = Encoding.UTF8.GetBytes(stringToEncrypt);
            //var cryptoServiceProvider = new MD5CryptoServiceProvider();
            //byte[] keyArray = cryptoServiceProvider.ComputeHash(Encoding.UTF8.GetBytes(SecurityKey));
            //cryptoServiceProvider.Clear();
            //var tripleDesCryptoServiceProvider = new TripleDESCryptoServiceProvider
            //                                          {
            //                                              Key = keyArray,
            //                                              Mode = CipherMode.ECB,
            //                                              Padding = PaddingMode.PKCS7
            //                                          };

            //ICryptoTransform cryptoTransform = tripleDesCryptoServiceProvider.CreateEncryptor();
            //byte[] resultArray = cryptoTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
            //tripleDesCryptoServiceProvider.Clear();
            //return Convert.ToBase64String(resultArray, 0, resultArray.Length);
        }
Esempio n. 27
0
    // Used to save the specified profile.

    public static void SaveProfile(string path, string profileImage, string profileName, string profileId, string fullProfileName)
    {
        ProfileData profile = CreateProfile(profileId, profileImage, profileName, fullProfileName, false);

        if (profile == null)
        {
            return;
        }

        string json = JsonUtility.ToJson(profile);

        // Creates the unique Encryption key per profile
        string JSON_ENCRYPTED_KEY = fullProfileName + "*},+;))%.<'){>')']$-$-`=([{+\'" + fullProfileName + "&@";

        // If the key is shorter then 32 characters it will make it longer
        if (JSON_ENCRYPTED_KEY.Length < 33)
        {
            while (JSON_ENCRYPTED_KEY.Length < 33)
            {
                JSON_ENCRYPTED_KEY = fullProfileName + "*},+;))%.<'){>')']$-$-`=([{+\'" + fullProfileName + "&@" + fullProfileName;
            }
        }
        // If the value is longer then 32 characters it will make it 32 characters
        if (JSON_ENCRYPTED_KEY.Length > 32)
        {
            JSON_ENCRYPTED_KEY = StringExtensions.Truncate(JSON_ENCRYPTED_KEY, 32);
        }

        // Encryption process
        Rijndael crypto = new Rijndael();

        byte[] soup = crypto.Encrypt(json, JSON_ENCRYPTED_KEY);
        File.WriteAllBytes(path, soup);

        ProfilesData profiles = CreateProfilesData(profileId, profileName, fullProfileName);

        LoadAllProfiles(ProfilesPath);

        SaveManager.profiles.Add(profiles);

        SaveAllProfiles(ProfilesPath);
        SaveManagerEvents.current.ProfileSaved(profile);
    }
Esempio n. 28
0
    // Save Game
    public static async Task SaveGameAsync(bool hasPlayed, int balance, Vector3 playerPosition, Quaternion playerRotation, Vector3 cameraPosition, Quaternion cameraRotation)
    {
        if (SelectedProfileManager.selectedProfile == null)
        {
            return;
        }

        string fullProfileName = SelectedProfileManager.selectedProfile.fullProfileName;

        GameData gameData = CreateGameData(hasPlayed, balance, playerPosition, playerRotation, cameraPosition, cameraRotation);

        if (gameData == null)
        {
            return;
        }

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

        if (!Directory.Exists(dirPath))
        {
            FileManagerExtension.CreateDirectory(dirPath);
        }

        string json = JsonUtility.ToJson(gameData);

        // 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);
        }

        // Encryption process
        Rijndael crypto = new Rijndael();

        byte[] soup = crypto.Encrypt(json, jsonEncryptedKey);
        await AsyncHelperExtensions.WriteBytesAsync(path, soup);

        SaveManagerEvents.current.SaveGame(gameData, SelectedProfileManager.selectedProfile);
    }
        public async Task <ActionResult> ResetPassword(User model)
        {
            model.Email = Encoding.UTF8.GetString(Convert.FromBase64String(model.Email));

            var _user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email && u.IsDataActive);

            if (_user != null)
            {
                _user.AuthString = Rijndael.Encrypt(string.Concat(_user.Username, model.Password));
                await db.SaveChangesAsync();

                TempData["Notification"] = new Notification("Success", "Your password has been changed successfully.");
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["Notification"] = new Notification("Error", "Sorry unable to process your request. please try later.");
                return(RedirectToAction("Index"));
            }
        }
Esempio n. 30
0
        private static void EncryptDecryptKnownECB192(Rijndael alg)
        {
            byte[] plainTextBytes =
                new ASCIIEncoding().GetBytes("This is a sentence that is longer than a block, it ensures that multi-block functions work.");

            byte[] encryptedBytesExpected = new byte[]
            {
                0xC9, 0x7F, 0xA5, 0x5B, 0xC3, 0x92, 0xDC, 0xA6,
                0xE4, 0x9F, 0x2D, 0x1A, 0xEF, 0x7A, 0x27, 0x03,
                0x04, 0x9C, 0xFB, 0x56, 0x63, 0x38, 0xAE, 0x4F,
                0xDC, 0xF6, 0x36, 0x98, 0x28, 0x05, 0x32, 0xE9,
                0xF2, 0x6E, 0xEC, 0x0C, 0x04, 0x9D, 0x12, 0x17,
                0x18, 0x35, 0xD4, 0x29, 0xFC, 0x01, 0xB1, 0x20,
                0xFA, 0x30, 0xAE, 0x00, 0x53, 0xD4, 0x26, 0x25,
                0xA4, 0xFD, 0xD5, 0xE6, 0xED, 0x79, 0x35, 0x2A,
                0xE2, 0xBB, 0x95, 0x0D, 0xEF, 0x09, 0xBB, 0x6D,
                0xC5, 0xC4, 0xDB, 0x28, 0xC6, 0xF4, 0x31, 0x33,
                0x9A, 0x90, 0x12, 0x36, 0x50, 0xA0, 0xB7, 0xD1,
                0x35, 0xC4, 0xCE, 0x81, 0xE5, 0x2B, 0x85, 0x6B,
            };

            byte[] aes192Key = new byte[]
            {
                0xA6, 0x1E, 0xC7, 0x54, 0x37, 0x4D, 0x8C, 0xA5,
                0xA4, 0xBB, 0x99, 0x50, 0x35, 0x4B, 0x30, 0x4D,
                0x6C, 0xFE, 0x3B, 0x59, 0x65, 0xCB, 0x93, 0xE3,
            };

            // The CipherMode and KeySize are different than the default values; this ensures the type
            // forwards the state properly to Aes.
            alg.Mode = CipherMode.ECB;
            alg.Key  = aes192Key;

            byte[] encryptedBytes = alg.Encrypt(plainTextBytes);
            Assert.Equal(encryptedBytesExpected, encryptedBytes);

            byte[] decryptedBytes = alg.Decrypt(encryptedBytes);
            Assert.Equal(plainTextBytes, decryptedBytes);
        }
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 byte[] Encode(string stringToEncode)
 {
     Rijndael coder = new Rijndael(Key);
     return coder.Encrypt(stringToEncode);
 }