yuvarajupadhyaya

EncodingDecoding

May 8th, 2022
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5.  
  6. namespace Merokhaja.Service.Security
  7. {
  8.     public static class CryptoUtilities
  9.     {
  10.         public static string EncryptString(string text)
  11.         {
  12.             string encrypted;
  13.             try
  14.             {
  15.                 byte[] b = System.Text.Encoding.ASCII.GetBytes(text);
  16.                 encrypted = Convert.ToBase64String(b);
  17.                
  18.             }
  19.             catch (FormatException e)
  20.             {
  21.                 encrypted = "";
  22.             }
  23.             return encrypted;
  24.  
  25.         }
  26.        
  27.         public static string DecryptString(string text)
  28.         {
  29.             byte[] b;
  30.             string decrypted;
  31.             try
  32.             {
  33.                 b = Convert.FromBase64String(text);
  34.                 decrypted = System.Text.Encoding.ASCII.GetString(b);
  35.  
  36.             }
  37.             catch (FormatException e)
  38.             {
  39.                 decrypted = "";
  40.             }
  41.             return decrypted;
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment