JS implements encryption

Front-end JS encryption here introduces two encryption methods

js encryption only needs to import the required encryption js

The first encryption method

BASE64 encryption method, first import the required JS, and then import the required js script in the js file is OK

Let's take a look at the code

<!DOCTYPE html>
<html lang="en">
<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 js file BASE64 is introduced here. If you want to encrypt the password on the login page and directly call encode for a long time, you can directly encrypt it. Decrypt directly calls the decode method.

 

The second method uses MD5 encryption

I believe everyone is familiar with it, yes, MD5 encryption front-end background can be used,

First download the MD5 compressed package and unzip it

Import the decompressed MD5 file into the project you need to encrypt

<!DOCTYPE html>
<html lang="en">
<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 refer to the MD5 file in js, and directly call the MD5 encryption method in the string that needs to be encrypted, is it very simple?

Let's take a look at the encrypted string

 

发布了105 篇原创文章 · 获赞 536 · 访问量 7万+

Guess you like

Origin blog.csdn.net/qq_41934990/article/details/81878797
Recommended