几种常用的前端加密

Posted c-target

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了几种常用的前端加密相关的知识,希望对你有一定的参考价值。

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>

 

以上是关于几种常用的前端加密的主要内容,如果未能解决你的问题,请参考以下文章

前端js几种加密/解密方法

前端js几种加密/解密方法

Android 的几种加密方式

前端AES + RSA加密

记录一下前端使用CryptoJS的几种加密方式

前端常用的加密方法