js几种加密方法

1.base64加密

它的github地址:https://github.com/dankogai/js-base64

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" >
        <title>base64加密</title>
        <script type="text/javascript" src="base64.min.js"></script>
        <script type="text/javascript">
            var encodebefore = Base64.encode("mosquito~");          
            console.log("base64 encode:" + encodebefore);
            var encodeafter = Base64.decode(encodebefore);//解密          
            console.log("base64 decode:" + encodeafter);  
        </script>  
    </head>
    <body>
    
    </body>
</html>

2.MD5加密(不可逆)

github地址:https://github.com/blueimp/JavaScript-MD5

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" >
        <title>md5加密</title>
        <script type="text/javascript" src="md5.min.js"></script>
        <script type="text/javascript">
            var md5encode = md5("mosquito~");         
            console.log("md5 encode:" + md5encode);     
            var objencode = md5("name", "mosquito");       
            console.log("md5 encode:" + objencode);
            const salt = 'This_is_salt'
            var saltencode= md5('mosquito'+salt);//一般md5需要加盐处理
            console.log("md5 salt encode:" + saltencode); 
        </script>  
    </head>
    <body>
    
    </body>
</html>

3.sha1加密(不可逆)

github地址:https://github.com/emn178/js-sha1

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" >
        <title>sha1加密</title>
        <script type="text/javascript" src="sha1.js"></script>
        <script type="text/javascript">
            var sha1encode = sha1("mosquito~"); 
            console.log("sha1 encode:" + sha1encode);
        </script>  
    </head>
    <body>
    
    </body>
</html>

 4.编码和解码字符串

使用JavaScript函数的escape()和unescape(),分别是编码和解码字符串,

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="utf-8" >
        <title>编码和解码字符串</title>
        <script type="text/javascript">
            var escape1 =escape("我的名字是:mosquito~");//编码
            console.log("escape:" + escape1);
            var unescape1 = unescape(escape1); 
            console.log("unescape:" + unescape1);
        </script>  
    </head>
    <body>
    
    </body>
</html>

 demo传送门:https://github.com/ouxiaojie18/all-demo/tree/master/%E5%8A%A0%E5%AF%86

posted @ 2018-10-09 13:54  mosquito~  阅读(13619)  评论(0编辑  收藏  举报