public int OnExecute() { try { var codec = new AnsibleVaultCodec(); using (var stm = ArgumentUtil.GetInputStream(FilePath)) using (var ostm = ArgumentUtil.GetOutputStream(OutputPath, true)) { using (var sr = new StreamReader(stm, Encoding.UTF8)) { codec.Decode(sr, ArgumentUtil.GetPassword(Password, Passfile, PassEnv), ostm); } } } catch (Exception e) { Console.Error.WriteLine($"decoding error: {e}"); return(1); } return(0); }
public int OnExecute() { try { var codec = new AnsibleVaultCodec(); using (var stm = ArgumentUtil.GetInputStream(FilePath)) using (var ostm = ArgumentUtil.GetOutputStream(OutputPath, true)) { using (var sw = new StreamWriter(ostm, new UTF8Encoding(false))) { var lst = new List <byte>(); var buf = new byte[4096]; while (true) { var bytesread = stm.Read(buf, 0, 4096); if (bytesread <= 0) { break; } lst.AddRange(buf.Take(bytesread)); } var eolString = ArgumentUtil.EolOptionToEolString(EndOfLine); if (eolString != null) { sw.NewLine = eolString; } codec.Encode(lst.ToArray(), ArgumentUtil.GetPassword(Password, Passfile, PassEnv), CreateSalt(), sw, Label, 80); } } } catch (Exception e) { Console.Error.WriteLine($"error in encoding: {e}"); return(1); } return(0); }