Home / the Internet / Web programming / How to encrypt a string

How to encrypt a string

/
50 Views

How to encrypt a string</a>

The need to encrypt a string variable in web programming arises quite often.

It may be necessary not only to work withPasswords or other private data. For example, it is often easier to encrypt the html code that needs to be saved to a file, database or cookies than to clean it from all prohibited characters before writing, and then restore them after reading.

Below is one of the options for encrypting a string variable using the PHP language.

Instructions

    1

Use the built-in function of the PHP languageBase64_encode for encoding string variables. It has only one parameter to pass - the value of the encrypted variable. For example, the PHP code that will output the text "encrypted string" encoded by the MIME base64 method to the page may look like this:
& Lt-? Php echo base64_encode ('encrypted string') -? & Gt-
The encoded text will be: "5 + D46PTw7uLg7e3g / yDx8vDu6uA =".

    2

Use the built-in function base64_decode forDecoding of string variables, encrypted using the MIME base64 method. This function also has only one mandatory parameter. For example, to decode and display the code from the previous step, you can use this line in PHP:
& Lt-? Php echo base64_decode ('5 + D46PTw7uLg7e3g / yDx8vDu6uA =') -? & Gt-

    3

Use any web service if you encode a word or test one by one or if you can not execute PHP scripts. For example, by going to the page http://tools4noobs.com/online_php_functions/base64_encode Enter the desired word in the single field orText and click on the button labeled Base 64 encode. The script on the server will receive the data entered, apply the base64_encode function to them, and place the encoded value in an additional input field. In it, the encrypted string can be copied and used at your discretion. If you need to decrypt, you can use a similar web service that will apply the function base64_decode to the value you entered. The corresponding page on this site is available at http://tools4noobs.com/online_php_functions/base64_decode.

How to encrypt a string Was last modified: June 20th, 2017 By Pyimaans
It is main inner container footer text