We help IT Professionals succeed at work.
Get Started

c# Basic Encyption/Decryption

MooksUK
MooksUK asked
on
386 Views
Last Modified: 2012-06-21
Hi,

I have created a function based upon something from VB6 which allows me to encrypt/decrypt some basic information. The encryption works fine but when I attempt to use the same function to decrypt not all characters are converted correctly.

I can not change the encryption method from this Xor method as the data which is encrypted is used by many programs written in different languages. Hence I have adopted it from VB6.

Any ideas why it would encrypt OK but have problems decrypting?? Any help greatly appreciated.

        public static string EncryptPW(string p)
        {
           
            //Encrypt password
            string strResult = "";
            char testChar;
            for (int i = 0; i < p.Length; i++)
            {
                testChar = Convert.ToChar(p.Substring(i, 1));
                strResult += (char)(testChar ^ 255);
            }

            return strResult;
        }
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE