public void Entity_SetValue_str_object_EncryptVarios_ret_void()
        {
            // Prepara
            EntityEncryptHashVariosDemo entity = new EntityEncryptHashVariosDemo();
            Encryptor encrip = new Encryptor();

            // campoAByteCorto
            byte[] campoAByteCorto       = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            byte[] cortoEncrypted        = encrip.EncryptBytes(campoAByteCorto);
            byte[] cortoLenght           = Convierte.IntToBytes(cortoEncrypted.Length);
            byte[] campoAByteCortoFuente = cortoLenght.Concat(cortoEncrypted).ToArray();

            // campoAByteLargo
            List <byte> bytes = new List <byte>();

            for (int i = 0; i < 1000; i++)
            {
                bytes.Add(Convert.ToByte(i % 256));
            }
            byte[] campoAByteLargo = bytes.ToArray();
            byte[] largoToEncrypt  = new byte[100];
            Array.Copy(campoAByteLargo, largoToEncrypt, largoToEncrypt.Length);
            byte[] largoNoEncrypted = new byte[900];
            Array.Copy(campoAByteLargo, 100, largoNoEncrypted, 0, largoNoEncrypted.Length);
            byte[] largoEncrypted        = encrip.EncryptBytes(largoToEncrypt);
            byte[] largoLenght           = Convierte.IntToBytes(largoEncrypted.Length);
            byte[] campoAByteLargoFuente = largoLenght.Concat(largoEncrypted).Concat(largoNoEncrypted).ToArray();
            byte[] bytesToHashLargo      = new byte[100];
            Array.Copy(campoAByteLargoFuente, bytesToHashLargo, bytesToHashLargo.Length);

            // Ejecuta
            Encryptor encriptor = new Encryptor();

            entity.SetValue("Clave", "key");
            entity.SetValue("CampoInt", encriptor.Encrypt("17"));
            entity.SetValue("CampoDouble", encriptor.Encrypt("145.96"));
            entity.SetValue("CampoStr", encriptor.Encrypt("este es un texto corto"));
            entity.SetValue("CampoAByteCorto", campoAByteCortoFuente);
            entity.SetValue("CampoAByteLargo", campoAByteLargoFuente);
            entity.SetValue("Hash", null);

            // Comprueba
            Assert.AreEqual("key", entity.Clave);
            Assert.AreEqual(17, entity.CampoInt);
            Assert.AreEqual(145.96, entity.CampoDouble);
            Assert.AreEqual("este es un texto corto", entity.CampoStr);
            Assert.AreEqual(campoAByteCorto, entity.CampoAByteCorto);
            Assert.AreEqual(campoAByteLargo, entity.CampoAByteLargo);
            string fields = string.Concat("key", encriptor.Encrypt("17"), encriptor.Encrypt("145.96"), encriptor.Encrypt(entity.CampoStr),
                                          Convert.ToBase64String(campoAByteCortoFuente),
                                          Convert.ToBase64String(bytesToHashLargo));
            HashGenerator hg           = new HashGenerator();
            string        hashGenerado = hg.GetHashCode(fields);

            Assert.AreEqual(hashGenerado, entity.Hash);
        }
        public void Entity_GetValue_str_EncryptVarios_ret_object()
        {
            // Prepara
            EntityEncryptHashVariosDemo entity = new EntityEncryptHashVariosDemo();

            entity.Clave           = "key";
            entity.CampoInt        = 17;
            entity.CampoDouble     = 145.96;
            entity.CampoStr        = "este es un texto corto";
            entity.CampoAByteCorto = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
            List <byte> bytes = new List <byte>();

            for (int i = 0; i < 1000; i++)
            {
                bytes.Add(Convert.ToByte(i % 256));
            }
            entity.CampoAByteLargo = bytes.ToArray();

            // Ejecuta
            string clave       = (string)entity.GetValue("Clave");
            string campoDouble = (string)entity.GetValue("CampoDouble");
            string campoInt    = (string)entity.GetValue("CampoInt");
            string campoStr    = (string)entity.GetValue("CampoStr");

            byte[] campoAByteCorto = (byte[])entity.GetValue("CampoAByteCorto");
            byte[] campoAByteLargo = (byte[])entity.GetValue("CampoAByteLargo");
            string hash            = (string)entity.GetValue("Hash");

            // Comprueba
            Encryptor encriptor = new Encryptor();

            Assert.AreEqual("key", clave);
            Assert.AreEqual(encriptor.Encrypt("17"), campoInt);
            Assert.AreEqual(encriptor.Encrypt("145.96"), campoDouble);
            Assert.AreEqual(encriptor.Encrypt(entity.CampoStr), campoStr);

            // Assert.AreEqual para CampoAByteCorto
            byte[] bytesEncryptLength = new byte[4];
            Array.Copy(campoAByteCorto, bytesEncryptLength, bytesEncryptLength.Length);
            int encryptLength = Convierte.BytesToInt(bytesEncryptLength);

            byte[] bytesEncrypted = new byte[encryptLength];
            Array.Copy(campoAByteCorto, 4, bytesEncrypted, 0, bytesEncrypted.Length);
            Assert.AreEqual(encriptor.EncryptBytes(entity.CampoAByteCorto), bytesEncrypted);

            // Assert.AreEqual para CampoAByteLargo
            Array.Copy(campoAByteLargo, bytesEncryptLength, bytesEncryptLength.Length);
            encryptLength  = Convierte.BytesToInt(bytesEncryptLength);
            bytesEncrypted = new byte[encryptLength];
            Array.Copy(campoAByteLargo, 4, bytesEncrypted, 0, bytesEncrypted.Length);
            byte[] bytesNoEncrypted = new byte[campoAByteLargo.Length - (4 + encryptLength)];
            Array.Copy(campoAByteLargo, 4 + encryptLength, bytesNoEncrypted, 0, bytesNoEncrypted.Length);
            byte[] bytesToEncrypt = new byte[100];
            Array.Copy(entity.CampoAByteLargo, bytesToEncrypt, 100);
            byte[] bytesNoEncryptedEsperados = new byte[bytesNoEncrypted.Length];
            Array.Copy(entity.CampoAByteLargo, 100, bytesNoEncryptedEsperados, 0, bytesNoEncryptedEsperados.Length);
            Assert.AreEqual(encriptor.EncryptBytes(bytesToEncrypt), bytesEncrypted);
            Assert.AreEqual(bytesNoEncryptedEsperados, bytesNoEncrypted);

            byte[] bytesToHashLargo = new byte[100];
            Array.Copy(campoAByteLargo, bytesToHashLargo, bytesToHashLargo.Length);
            string fields = string.Concat("key", encriptor.Encrypt("17"), encriptor.Encrypt("145.96"), encriptor.Encrypt(entity.CampoStr),
                                          Convert.ToBase64String(campoAByteCorto),
                                          Convert.ToBase64String(bytesToHashLargo));
            HashGenerator hg           = new HashGenerator();
            string        hashGenerado = hg.GetHashCode(fields);

            Assert.AreEqual(hashGenerado, hash);
        }