Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public static class BaseHelper
  2. {
  3. public static void EncryptFile(string filename, string output)
  4. {
  5. if (File.Exists(filename))
  6. {
  7. string b64 = Convert.ToBase64String(EncodingDef(File.ReadAllText(filename)));
  8. File.WriteAllText(output, b64);
  9. }
  10. }
  11.  
  12. public static void DecryptFile(string filename, string output)
  13. {
  14. if (File.Exists(filename))
  15. {
  16. byte[] bb = Convert.FromBase64String(filename);
  17. string save = EncodingUtf8(bb);
  18. File.WriteAllText(output, save);
  19. }
  20. }
  21.  
  22. private static byte[] EncodingDef(string file) =>
  23. Encoding.Default.GetBytes(file);
  24. private static string EncodingUtf8(byte[] file) =>
  25. Encoding.ASCII.GetString(file);
  26. }
  27.  
  28. string filename = "1.txt";
  29. BaseHelper.EncryptFile(filename, "1_enc.txt");
  30. BaseHelper.DecryptFile("1_enc.txt", "1.dec.txt");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement