+ Reply to Thread
Results 1 to 2 of 2

Thread: Encode/Decode base64 strings

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    45

    Encode/Decode base64 strings

    I want to Encode/Decode strings using base64 as i don't want the basic user to understand some values inside application and i don't want to use a powerful encrypting algorithm.
    Last edited by zackvv; 11-09-2012 at 12:14 AM.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    27
    But before going into it , just remember : this is the easiest encryption method that can be decrypted in a matter of seconds using some online website, but as long as the test you are encrypting is not critical then that is okay.

    Here is the snippet :

    Encrypt :
    Code:
            public static string EncodeTo64(string toEncode)
            {
                byte[] toEncodeAsBytes = System.Text.Encoding.ASCII.GetBytes(toEncode);
                string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
                return returnValue;
            }
    Decrypt :
    Code:
            public static string DecodeFrom64(string encodedData)
            {
                byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
                string returnValue = System.Text.Encoding.ASCII.GetString(encodedDataAsBytes);
                return returnValue;
            }
    How to get the Encoded text ?
    Code:
    string encoded = EncodeTo64("My name is Zack");
    Console.WriteLine(encoded);
    That will generate an encoded string :
    Code:
    TXkgbmFtZSBpcyBaYWNr
    How to get the Decoded text ?
    Code:
    string encoded1 = DecodeFrom64("TXkgbmFtZSBpcyBaYWNr");
    Console.WriteLine(encoded1);

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts