String encryption using C#

The following code will help you to encrypt a string.

 

public string EncryptString(string strInput)

        {

            int i = 0;

            string strTemp = null;

            for (i = 0; i <= strInput.Length - 1; i++)

            {

                int charValue = Convert.ToInt32(strInput[i]); // converting in ascii

                charValue ^= 30;

                strTemp += char.ConvertFromUtf32(charValue);

            }

 

            return strTemp;

        }

 

//Pass your string to this function and ‘strTemp’ will return the encrypted string.

 

Note: After encryption, we can use same function to decrypt a encrypted string.

Ebook Download
View all
FileInfo in C#
Read by 9.7k people
Download Now!
Learn
View all