Javascript-base64_encode of php on the server side is encrypted and pushed to the front-end.

Source: Internet
Author: User
Today I read a piece of code to implement the following functions: the server php calls the underlying command, use base64_encode to encrypt the returned results. frontend. js uses the GET method to call the above php to obtain the encrypted text and use the following decryption function to decrypt it. The English is correct, but the Chinese characters are garbled. {Code...} question... today I read a piece of code to implement the following functions:

  1. The server php calls the underlying command to encrypt the returned results with base64_encode.
  2. The front-end js uses the GET method to call the above php to obtain the encrypted text and use the following decryption function for decryption. The English language is correct, but the Chinese characters are garbled.
        decode_base64_str:function (s) {                var e={},i,k,v=[],r='',w=String.fromCharCode;                var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];                for(z in n){for(i=n[z][0];i
  
   =8){r+=w((b>>>(l-=8))%256);}                        }                }                return r;        },
  
Problem:
  1. If Chinese characters are not displayed during the encryption and decryption process, is there any risk?
  2. To decrypt Chinese characters perfectly, which of the above decryption functions is wrong?

Corrected that the strings after encode are directly transmitted through GET between js and php.

PS: I'm not sure whether base64_encode is necessary. The risk I'm talking about is not the leakage of transmitted content, but whether there are risks such as injection, currently, I know that injection occurs when the front end is submitted to the backend. Others are not very familiar.

Reply content:

Today I read a piece of code to implement the following functions:

  1. The server php calls the underlying command to encrypt the returned results with base64_encode.
  2. The front-end js uses the GET method to call the above php to obtain the encrypted text and use the following decryption function for decryption. The English language is correct, but the Chinese characters are garbled.
        decode_base64_str:function (s) {                var e={},i,k,v=[],r='',w=String.fromCharCode;                var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];                for(z in n){for(i=n[z][0];i
  
   =8){r+=w((b>>>(l-=8))%256);}                        }                }                return r;        },
  
Problem:
  1. If Chinese characters are not displayed during the encryption and decryption process, is there any risk?
  2. To decrypt Chinese characters perfectly, which of the above decryption functions is wrong?

Corrected that the strings after encode are directly transmitted through GET between js and php.

PS: I'm not sure whether base64_encode is necessary. The risk I'm talking about is not the leakage of transmitted content, but whether there are risks such as injection, currently, I know that injection occurs when the front end is submitted to the backend. Others are not very familiar.

php$ Base = base64_encode (urlencode ('Chinese'); // response. log (decodeURIComponent (decode_base64_str ('juu0jui4jufejuu2jtk2jtg3 '); // Chinese

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.