Exemple #1
0
        private void btnUploadImage_Click(object sender, EventArgs e)
        {
            var isValidated = ValidateBeforeUpload();

            if (isValidated)
            {
                //bool postSuccess = false;
                int      i = 0, j = 0;
                UInt32[] llave      = new UInt32[4];
                UInt32[] vectorinit = new UInt32[4];
                foreach (char x in txtKey.Text)
                {
                    llave[i] = UInt32.Parse(x.ToString());
                    i++;
                }

                foreach (char x in txtIV.Text)
                {
                    vectorinit[j] = UInt32.Parse(x.ToString());
                    j++;
                }

                Byte[] encrypt = Encrypt(txtNameImg.Text, (Bitmap)picBox.Image);

                Encript encriptar = new Encript(llave, vectorinit);
                encriptar.inicializacion();
                encriptar.generateKeyStream((encrypt.Length) / 4);

                Byte[] ciphertext = encriptar.generateCiphertext(encrypt);

                Upload(txtNameImg.Text, ciphertext);
            }
        }
Exemple #2
0
        private async Task DecryptFile()
        {
            ImgAPI imgApi = await API.GetImageDetail(txtIPServer.Text, listFiles.SelectedItem.ToString());

            if (imgApi != null)
            {
                Byte[] bytes = Convert.FromBase64String(imgApi.imageByteArray);

                //Desencripción:
                int      i = 0, j = 0;
                UInt32[] llave      = new UInt32[4];
                UInt32[] vectorinit = new UInt32[4];
                foreach (char x in txtKey.Text)
                {
                    llave[i] = UInt32.Parse(x.ToString());
                    i++;
                }

                foreach (char x in txtIV.Text)
                {
                    vectorinit[j] = UInt32.Parse(x.ToString());
                    j++;
                }
                Encript desencriptar = new Encript(llave, vectorinit);
                desencriptar.inicializacion();
                desencriptar.generateKeyStream((bytes.Length) / 4);

                Byte[] plaintext = desencriptar.generateCiphertext(bytes);

                Bitmap bitmap = ConvertImg.ToBitMap(plaintext);

                picBox.Image = bitmap;
            }
            else
            {
                ShowMessage("Error al descargar la imagen.", true);
            }
        }