encryption - cant decrypt a file in c#, the resulting file is corrupted -


i created code in visual studio download file using ftp download methods , tried create code decrypt when ia realized files encrypted (i have key , iv) tried make code decrypt file result corrupted)

private static void decryptfile(string path, string newpath, string skey)     {         try         {             using (rijndaelmanaged aes = new rijndaelmanaged() {                  keysize = 128,                 mode = ciphermode.cbc              })             {                 byte[] key = asciiencoding.utf8.getbytes(skey);                   byte[] iv = asciiencoding.utf8.getbytes(skey);                  using (filestream fscrypt = new filestream(inputfile, filemode.open))                 {                     using (filestream fsout = new filestream(outputfile, filemode.create))                     {                         using (icryptotransform decryptor = aes.createdecryptor(key, iv))                         {                             using (cryptostream cs = new cryptostream(fscrypt, decryptor, cryptostreammode.read))                             {                                 int data;                                 while ((data = cs.readbyte()) != -1)                                 {                                     fsout.writebyte((byte)data);                                 }                             }                         }                     }                 }             }         }         catch (exception ex)         {             // failed decrypt file         }     } 


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -