public bool encryptSym(string source, string destination) { AesEncryptie symEncryptor = new AesEncryptie(); inputHasher = new hasher(); outputHasher = new hasher(); FileInfo info = new FileInfo(source); input = new FileIO(source); output = new FileIO(destination); try { writeBegin(info.Name, program_encryptor.run_encrypt(symEncryptor.KEY), program_encryptor.run_encrypt(symEncryptor.IV)); } catch (FileNotFoundException ex) { throw new Exceptions("File not found:" + ex.FileName, "Encryptie"); } catch (FileLoadException ex) { throw new Exceptions("Geen toegangsrechten:" + ex.FileName, "Encryptie"); } int count; byte[] hulp; input.OpenRead(); while ((count = input.Read_part()) > 0) { inputHasher.Add_part(input.buffer); hulp = symEncryptor.encrypt(input.buffer); outputHasher.Add_part(hulp); output.Write_line(hulp); } symEncryptor.end_encryption(); input.close_file(); writeEnd(); output.Writer_close(); return(true); }
public bool decryptSym(string source, string destination) { AesEncryptie symEncryptor; inputHasher = new hasher(); outputHasher = new hasher(); string filename = ""; byte[] key = new byte[0]; byte[] IV = new byte[0]; input = new FileIO(source); try { ReadBegin(ref filename, ref key, ref IV); } catch (Exceptions ex) { throw new Exceptions("Wegschrijven lukte niet:" + ex.Message, "Decryptie"); } try { FileInfo info = new FileInfo(filename); FileInfo infoDestination = new FileInfo(destination); if (!infoDestination.Extension.Equals(info.Extension)) { output = new FileIO(destination, info.Extension); } else { output = new FileIO(destination); } symEncryptor = new AesEncryptie(program_encryptor.run_decrypt(IV), program_encryptor.run_decrypt(key)); byte[] hulp; output.OpenWrite(); while (input.readCode() > 0) { inputHasher.Add_part(input.buffer); hulp = symEncryptor.encrypt(input.buffer); outputHasher.Add_part(hulp); output.Write_part(hulp); } symEncryptor.end_encryption(); Check_Hashes(); } catch (Exceptions ex) { throw new Exceptions("Er is geknoeit met de input files:" + ex.Message, "Decryptie"); } output.close_file(); return(true); }