zoukankan      html  css  js  c++  java
  • 关于前端数据加密

    什么是前端加密

      前端加密就是在客户端对用户要提交的内容进行加密,从而降低服务器端的压力。

    为什么要进行前端加密

       进行前端加密值后,要对密码进行破译和破解,则需要在客户端方面消耗更多的资源,延长了破解时间,从而获得了更高的安全性。

    前端加密方式:

    • https,安全性高。证书认证,一种是来自于证书颁发机构;一种是自己生成证书,但需要浏览器添加信任;成本高。
    • post之前,通过js对密码进行加密。前端js:md5+salt(随机数),后台服务器php : 截取salt后的数与数据库的密码进行比较;生成密码:md5()
    • 用RSA进行加密传输
    • 使用密码空间,进行加密传输
    • 有服务端颁发并验证一个带有时间戳的可信token

    在固定字符串上截取随机长度和打乱顺序的字符串

    function randomString(length) {
        var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
       
        if (! length) {
            length = Math.floor(Math.random() * chars.length);
        }
       
        var str = '';
        for (var i = 0; i < length; i++) {
            str += chars[Math.floor(Math.random() * chars.length)];
        }
        return str;
    }

     RSA加密

    1. 后端先给前端发放一个公钥(public-key)
    2. 前端使用公钥对密码(password)等敏感字段进行加密
    3. 前端使用post方式将使用公钥加密后的密码发送到后端
    4. 后端使用私钥(private-key)进行解密,获得原密码

    MD5实现的前端加密

    • MD5定义

      MD5 is a secure hash algorithm. It takes a string as input, and produces a 128-bit number, the hash. The same string always produces the same hash, but given a hash, it is not generally possible to determine the original string. Secure hash algorithms are useful for protecting passwords and ensuring data integrity.

  • 相关阅读:
    入门activiti-------1简单运行
    JS对象、构造器函数和原型对象之间的关系
    myeclipse配背景色
    maven的pom.xml文件错误
    oracleXE简易版---使用基础
    ognl表达式注意事项
    Executors、ExecutorService、ThreadPoolExecutor
    ThreadPoolExecutor
    Phaser相位(工具的实战案例使用)
    ForkJoin
  • 原文地址:https://www.cnblogs.com/HXW-from-DJTU/p/6108611.html
Copyright © 2011-2022 走看看