Partage
  • Partager sur Facebook
  • Partager sur Twitter

Progression écriture CryptoFileStream

Récupéré le pourcentage accompli

    14 juillet 2019 à 1:26:46

    Bonjour,

    Je travaille actuellement sur un programme en .Net Core C# qui chiffre un fichier à l'aide du void suivant :

    private void EncryptFile(string source, string destination, string sKey)
            {
                FileStream fsInput = new FileStream(source,
                    FileMode.Open,
                    FileAccess.Read);
    
                FileStream fsEncrypted = new FileStream(destination,
                                FileMode.Create,
                                FileAccess.Write);
    
                DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
                DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                ICryptoTransform desencrypt = DES.CreateEncryptor();
                CryptoStream cryptostream = new CryptoStream(fsEncrypted,
                                    desencrypt,
                                    CryptoStreamMode.Write);
                byte[] bytearrayinput = new byte[fsInput.Length - 1];
                fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
                cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);
                cryptostream.Close();
                fsInput.Close();
                fsEncrypted.Close();
            }

    J'aimerais récupéré l'état d'avancement du chiffrement du fichier, j'ai tenté des petits trucs avec des while pour récupéré le nombre de bytes écrits mais du coup je n'arrive plus à utiliser la fonction de déchiffrement :

     private void DecryptFile(string source, string destination, string sKey)
            {
                DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
                //A 64 bit key and IV is required for this provider.
                //Set secret key For DES algorithm.
                DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                //Set initialization vector.
                DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
    
                //Create a file stream to read the encrypted file back.
                FileStream fsread = new FileStream(source,
                                               FileMode.Open,
                                               FileAccess.Read);
                //Create a DES decryptor from the DES instance.
                ICryptoTransform desdecrypt = DES.CreateDecryptor();
                //Create crypto stream set to read and do a 
                //DES decryption transform on incoming bytes.
                CryptoStream cryptostreamDecr = new CryptoStream(fsread,
                                                             desdecrypt,
                                                             CryptoStreamMode.Read);
                //Print the contents of the decrypted file.
                StreamWriter fsDecrypted = new StreamWriter(destination);
                fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd());
                fsDecrypted.Flush();
                fsDecrypted.Close();
            }

    Du coup j'aimerais récupéré l'avancement du chiffrement ou du déchiffrement peut importe la forme tant que cela peut être fait pendant le chiffrement ou le déchiffrement.

    Merci d'avance.


    • Partager sur Facebook
    • Partager sur Twitter

    Corentin-Aryox

      26 août 2019 à 14:32:33

      Pouvez-vous nous donner le code que vous avez fait ?

      Je ne vois pas pourquoi l'interpolation d'une valeur changerait le flux en sortie.

      • Partager sur Facebook
      • Partager sur Twitter
      Je recherche un CDI/CDD/mission freelance comme Architecte Logiciel/ Expert Technique sur technologies Microsoft.

      Progression écriture CryptoFileStream

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown