C # simplest text encryption,

Source: Internet
Author: User

C # simplest text encryption,

Private char [] TextEncrypt (string content, string secretKey) {char [] data = content. toCharArray (); char [] key = secretKey. toCharArray (); for (int I = 0; I <data. length; I ++) {data [I] ^ = key [I % key. length];} return data;} private string TextDecrypt (char [] data, string secretKey) {char [] key = secretKey. toCharArray (); for (int I = 0; I <data. length; I ++) {data [I] ^ = key [I % key. length];} return new string (data );}

The above is the simplest function for encrypting and decrypting text. It does not require the support of any database file, but only distinguishes the original text from the key in bytes. It is very easy to translate the ciphertext Back, take the password and the key to try again or try again.

If the key is correct, the correct original text will be returned. If the key is incorrect, the translation will be a bunch of garbled characters.

Therefore, it also provides the simplest encryption function.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.