Support Forums
[C#] Encrypt/Decrypt BASE64 - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [C#] Encrypt/Decrypt BASE64 (/showthread.php?tid=7013)



[C#] Encrypt/Decrypt BASE64 - xHtmlPhP - 05-13-2010

Here's the source, Learn from it don't just Copy/Paste.

Code:
#region using
using System;
#endregion

namespace EncryptAndDecrypt
{
    #region class
    class Program
    {
        #region main
        static void Main(string[] args)
        {
        start:
            Console.Clear();
            Console.WriteLine("Would you like to encrypt or decrypt?");
            String crypt = Console.ReadLine();
            if (crypt == "encrypt")
            {
                Console.Clear();
                Console.WriteLine("Text to encrypt:");
                String toEncode = Console.ReadLine();


                byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
                string returnvalue = System.Convert.ToBase64String(toEncodeAsBytes);
                Console.WriteLine(returnvalue);
                Console.WriteLine("\n\n\n");
                Console.WriteLine("Press Enter to continue...");
                Console.ReadLine();
                goto start;
            }
            if (crypt == "decrypt")
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("Text to decrypt:");
                    String decrypt = Console.ReadLine();
                    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                    System.Text.Decoder utf8Decode = encoder.GetDecoder();
                    byte[] todecode = Convert.FromBase64String(decrypt);
                    int charCount = utf8Decode.GetCharCount(todecode, 0, todecode.Length);
                    char[] decodedc = new char[charCount];
                    utf8Decode.GetChars(todecode, 0, todecode.Length, decodedc, 0);
                    string result = new String(decodedc);
                    Console.WriteLine(result);
                    Console.WriteLine("\n\n\n");
                    Console.WriteLine("Type 'Back' to go back to the start");
                    string read = Console.ReadLine();
                    if (read == "back")
                    {
                        goto start;
                    }

                }
                catch (Exception e)
                {
                    Console.WriteLine("\n\n");
                    Console.WriteLine("Error decoding");
                    Console.WriteLine("Type back to go back or info for info on the error.");
                    string readl = Console.ReadLine();
                    if (readl == "back")
                    {
                        goto start;
                    }
                    if (readl == "info")
                    {
                        Console.WriteLine("\n\n");
                        Console.WriteLine(e.ToString());
                        Console.ReadLine();
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Type 'Back' to go back");
                        string readb = Console.ReadLine();
                        if (readb == "back")
                        {
                            goto start;
                        }
                    }
                }
        #endregion main
            }
    #endregion class

        }
    }
}

Have fun Smile


RE: [C#] Encrypt/Decrypt BASE64 - //Pretext™ - 05-18-2010

More information would be nice.
Well as i can see your account is closed.
So this thread should be closed?


RE: [C#] Encrypt/Decrypt BASE64 - xHtmlPhP - 05-21-2010

(05-18-2010, 09:18 AM)//Pretext™ Wrote: More information would be nice.
Well as i can see your account is closed.
So this thread should be closed?

I was banned for a week due to posting a hacking tutorial.
Anyway i'm back now


RE: [C#] Encrypt/Decrypt BASE64 - SouR'D - 05-21-2010

Very nice Share Bro..>Did u code this???


RE: [C#] Encrypt/Decrypt BASE64 - xHtmlPhP - 05-21-2010

(05-21-2010, 08:16 PM)Optiikzz™ Wrote: Very nice Share Bro..>Did u code this???

Yes xD i wouldn't rip it then post Tongue This is probably the first thing i made in C# when i went from VB.NET to C#


RE: [C#] Encrypt/Decrypt BASE64 - Anxiety® - 05-22-2010

nice tut i like it. I like the fact people code C#. I <3 that language.


RE: [C#] Encrypt/Decrypt BASE64 - TurB0 - 05-24-2010

NIce share and good work Smile