码迷,mamicode.com
首页 > 其他好文 > 详细

几种常用的前端加密

时间:2019-08-11 17:28:40      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:ice   tle   htm   password   pat   base64   doc   div   size   

1、base64:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="base64.js"></script>
    <title>base64加密</title>
</head>
<body>
    <script>
        var rule = new Base64()
        var pwd = 123456 
        // 加密
        var encryption = rule.encode(password:+pwd)
        console.log(encryption) //cGFzc3dvcmQ6MTIzNDU2
        // 解密
        encryption = rule.decode(encryption); 
        console.log(encryption) //password:123456
    </script>
</body>
</html>

2、md5:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="md5.js"></script>
    <title>md5加密</title>
</head>
<body>
    <script>
        var pwd = 123456 
        // 加密
        var encryption = hex_md5(password:+pwd)
        console.log(encryption) //cc4452544b7f1a162452444f49238de8
    </script>
</body>
</html>

 

3、sha1

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="sha1.js"></script>
    <title>sha1加密</title>
</head>
<body>
    <script>
        var pwd = 123456 
        // 加密
        var encryption = hex_sha1(password:+pwd)
        console.log(encryption) //b48d0965a80dfad4ad6db7e98ce666d8226619bb
    </script>
</body>
</html>

 

4、RSA

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="jsencrypt.js"></script>
    <title>RSA加密</title>
</head>
<body>
    <script>
        var pwd = 123456 
        // 加密
        var encrypt = new JSEncrypt();
        var encryptStr = encrypt.encrypt(password :+pwd);
        console.log(encryptStr);//(每次都在变化)
        // 解密
        var decryptStr = encrypt.decrypt(encryptStr);
        console.log(decryptStr); //password :123456
    </script>
</body>
</html>

 

几种常用的前端加密

标签:ice   tle   htm   password   pat   base64   doc   div   size   

原文地址:https://www.cnblogs.com/C-target/p/11335444.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!