c# - Access to the path is denied (encryption) -


i trying encrypt hello.txt file failed. when encrypt, exception:

system.unauthorizedaccessexception: access path 'c:\users\username\desktop' denied. @ system.io.__error.winioerror(int32 errorcode, string maybefullpath) @ system.io.filestream.init(string path, filemode mode, fileaccess access, int32 rights, boolean userights, fileshare share, int32 buffersize, fileoptions options, security_attributes secattrs, string msgpath, boolean bfromproxy, boolean uselongpath, boolean checkhost) @ system.io.filestream..ctor(string path, filemode mode, fileaccess access) @ encrypt.encdec.decrypt(string filein, string fileout, string password) in c:\users\username\documents\my apps\encrypt\encrypt\form1.cs:line 518 @ encrypt.form1.proceededfe(string input, string output, string key) in c:\users\username\documents\my apps\encrypt\encrypt\form1.cs:line 154 

so here code (line 154):

    string inpute;     string outpute;     string pwde;      private void ofd1_click(object sender, eventargs e)     {         if (ofd.showdialog() == dialogresult.ok)         {             inpute = ofd.filename;         }     }      private void fbd1_click(object sender, eventargs e)     {         if(fbd.showdialog() == dialogresult.ok)         {             outpute = fbd.selectedpath;         }     }      private void encryptf_click(object sender, eventargs e)     {         pwde = keye.text;         if (inpute != null && outpute != null && pwde != null)         {             proceededfe(inpute, outpute, pwde);         }     }     private void proceededfe(string input, string output, string key)     {         try         {             encdec.decrypt(input, output, key); //line 154             donestat.text = "file decryption succeeded";         }         catch (exception ex)         {             donestat.text = "file decryption failed";             messagebox.show(convert.tostring(ex), "error");             donestattb.text = convert.tostring(ex);         }     } 

i copied code code project, encdec class decrypt method (line 518):

    // decrypt file file using password      public static void decrypt(string filein, string fileout, string password)     {          filestream fsin = new filestream(filein, filemode.open, fileaccess.read);         //line 518         filestream fsout = new filestream(fileout, filemode.openorcreate, fileaccess.write);           passwordderivebytes pdb = new passwordderivebytes(password,             new byte[] {0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d,          0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76});          rijndael alg = rijndael.create();          alg.key = pdb.getbytes(32);         alg.iv = pdb.getbytes(16);          cryptostream cs = new cryptostream(fsout,             alg.createdecryptor(), cryptostreammode.write);          int bufferlen = 4096;         byte[] buffer = new byte[bufferlen];         int bytesread;                  {             bytesread = fsin.read(buffer, 0, bufferlen);             cs.write(buffer, 0, bytesread);          } while (bytesread != 0);          cs.close();          fsin.close();     } 

how should fix this? there wrong in code?

you got system.io exception there nothing encryption...

check link handle it:

why access path denied?


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -