Need a poor man's encryption

Need a poor man's encryption

I have used AES (or is it EAS?) in my C# WinForms program. BUt for this aplication I was thinkg about something smaller and made up of small number of lines of code. It's not something that needs to be very secure. But I woud like it to be not usable as is.

Are there any simple algorithms that scramble and rename characters to otherwise make a mess out of a string?

This is for C#.

Thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
For simple string "encryption" you can just use Convert.ToBase64String():
        private void button1_Click(object sender, EventArgs e)
        {
            string str1 = textBox1.Text;

            // encrypt the string
            string str2 = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(str1));

            label1.Text = str2; // the "encrypted" string

            // convert it back
            string str3 = ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(str2));

            label2.Text = str3; // the "decrypted" string
        }

Open in new window

0
 
sam_gibsonCommented:
How about using a MD5 hash, if you can get away with one-way encryption?
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
newbiewebSr. Software EngineerAuthor Commented:
What's MD5 hash? Is there C# available for that?
0
 
priyank_gajeraCommented:
I am writing one function this works perfectly for me.
Please let me know is this helps or You need any other method.

public static string Encrypt(String plainText)
        {
            string encrypted = null;
            try
            {
                byte[] inputBytes = ASCIIEncoding.ASCII.GetBytes(plainText);
                byte[] pwdhash = null;
                MD5CryptoServiceProvider hashmd5;

                //generate an MD5 hash from the password. 
                //a hash is a one way encryption meaning once you generate
                //the hash, you cant derive the password back from it.
                hashmd5 = new MD5CryptoServiceProvider();
                pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
                hashmd5 = null;

                // Create a new TripleDES service provider 
                TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
                tdesProvider.Key = pwdhash;
                tdesProvider.Mode = CipherMode.ECB;

                encrypted = Convert.ToBase64String(
                    tdesProvider.CreateEncryptor().TransformFinalBlock(inputBytes, 0, inputBytes.Length));
            }
            catch (Exception e)
            {
                string str = e.Message;
                throw;
            }
            return encrypted;
        }

Open in new window

0
 
Rich RumbleSecurity SamuraiCommented:
No Rot-13 suggestion yet ;p http://dotnetperls.com/rot13 Much simpler in non-compiled languages, typically 1-3 lines of code... Here's TwoFish as well: http://www.schneier.com/twofish-download.html
-rich

0
 
newbiewebSr. Software EngineerAuthor Commented:
thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.