秦小小樱

导航

javascript Base64转码解码

javascript 使用btoa和atob来进行Base64转码和解码

$scope.checkAddCookie = function() {
            var expireDate = new Date();
            expireDate.setDate(expireDate.getDate() + 1);
            if ($scope.username && $scope.password && $scope.isRemembered) {
              $cookies.put("username",btoa($scope.username), { "expires": expireDate });
              $cookies.put("password",btoa($scope.password), { "expires": expireDate });
            }
          }

解码

function getLogin() {
            if ($cookies.get("username")) {
              $scope.username = atob($cookies.get("username"));
              if ($cookies.get("password")) {
                $scope.password = atob($cookies.get("password"));
              }
            } else {
              return null;
            }
          }

 

posted on 2018-10-22 16:15  RonnieQin  阅读(179)  评论(4编辑  收藏  举报