The content of this article is about the method of implementing encryption in js (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
Front-end JS encryption Here are two encryption methods
js encryption Just import the required encryption js
The first encryption method
BASE64 For the encryption method, first import the required JS, and then introduce the required js script into the js file.
Let’s take a look at the code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>base64加密</title> <script src="../jquery/jquery-1.8.0.min.js"></script> <script src="jquery.base64.js"></script> <script type="text/javascript"> var b = new Base64(); var str = b.encode("admin:admin"); alert("base64 encode:" + str); //解密 str = b.decode(str); alert("base64 decode:" + str); </script> </head> <body> <h3>base64 加密与解密</h3> </body> </html>
The BASE64 js file is introduced here , if you want to encrypt the password on the login page, directly call encode and wait for a long time to directly encrypt. To decrypt, directly call the decode method
The second method is to use MD5 encryption
I believe everyone does not It’s unfamiliar to you. Yes, MD5 encryption can be used in both front-end and backend.
First download the MD5 compressed package and decompress it
Import the decompressed MD5 file into the project you need to encrypt.
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>md5加密</title> <script src="md5.js"></script> <script type="text/javascript"> var hash = hex_md5("123dafd"); alert(hash) </script> </head> <body> </body> </html>
Directly reference the MD5 file in js, and directly call the MD5 encryption method in the string that needs to be encrypted. That’s it. Isn’t it very simple?
Let’s take a look at the encrypted string.
Related recommendations:
Three ways to modify element css style using javascript (code)
Introduction to common methods of obtaining element instructions in js (with code)
The above is the detailed content of How to implement encryption in js (with code). For more information, please follow other related articles on the PHP Chinese website!