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; } }