【发布时间】:2019-09-25 15:26:55
【问题描述】:
我需要使用加密参数从客户端 (JS) 调用 URL。然后我需要从它去往的服务器端控制器中解密 URL。
假设我有
window.location.href = "/app/submitted?docId=445";
我需要加密docId=445 部分。我可以使用atob/btoa 作为
window.location.href = "/app/submitted?" + atob("docId=445"); // Whole Param
window.location.href = "/app/submitted?docId=" + atob("445"); // Just the value
我更喜欢#1,但是在这两个中,当我来到我的 SpringMVC 控制器时,我将如何提取和解密这个参数?是否有相当于atob/btoa 的Java 加密?
@GetMapping("/app/submitted")
public ModelAndView submitted(HttpServletRequest request, HttpServletResponse response,
@RequestParam("docId") Integer docId) {
//...
// How to decrypt here (either whole param or just the value) from an atob/btoa?
}
或者我应该在这里使用编码而不是加密来保证两个层的等效性?我的目标是避免在地址栏中的任何位置显示 ID。
【问题讨论】:
标签: javascript java spring spring-mvc encryption