Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.IO;
- namespace base64cd
- {
- //BASE64 encoder/decoder
- class Program
- {
- static void PrintHelp()
- {
- string EXEName = Path.GetFileName (System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
- Console.WriteLine("BASE64 encoder/decoder");
- Console.WriteLine("Use:");
- Console.WriteLine(EXEName+" <-c|-d> <filename1> [filename2] [filename3] ... ");
- Console.WriteLine("-c - Encode to BASE64");
- Console.WriteLine("-d - Decode from BASE64");
- Console.WriteLine("filenameN - File name or file mask (*.txt, *.*, etc...)");
- }
- static void Main(string[] args)
- {
- string dir = "";
- if (args.Length < 2)
- {
- PrintHelp();
- return;
- };
- switch (args[0])
- {
- case "-c":
- {
- dir = Directory.GetCurrentDirectory(); //Current dir
- for (int i = 1; i < args.Length; i++)
- {
- string[] files = Directory.GetFiles(dir,
- args[i], SearchOption.TopDirectoryOnly); //find files
- if (files.Length < 1)
- {
- Console.WriteLine(args[i] + " not found");
- }
- else
- {
- foreach (string f in files)
- {
- Console.Write(f+": ");
- try
- {
- byte[] buf = File.ReadAllBytes(f);
- File.Copy(f, f + ".bak", true);
- string B64Str = Convert.ToBase64String(buf);
- File.WriteAllText(f, B64Str);
- Console.WriteLine("OK");
- }
- catch (Exception ex)
- {
- Console.WriteLine("ERROR " + ex.Message);
- }
- }
- }
- }
- }; break;
- case "-d":
- {
- dir = Directory.GetCurrentDirectory(); //Current dir
- for (int i = 1; i < args.Length; i++)
- {
- string[] files = Directory.GetFiles(dir,
- args[i], SearchOption.TopDirectoryOnly); //find files
- if (files.Length < 1)
- {
- Console.WriteLine(args[i] + " not found");
- }
- else
- {
- foreach (string f in files)
- {
- Console.Write(f + ": ");
- try
- {
- string B64Str = File.ReadAllText(f);
- File.Copy(f, f + ".bak", true);
- byte[] buf = Convert.FromBase64String(B64Str);
- File.WriteAllBytes(f, buf);
- Console.WriteLine("OK");
- }
- catch (Exception ex)
- {
- Console.WriteLine("ERROR " + ex.Message);
- }
- }
- }
- }
- };break;
- default:
- {
- PrintHelp();
- return;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement