-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckHashVerificationServlet.java
More file actions
40 lines (33 loc) · 1.7 KB
/
Copy pathCheckHashVerificationServlet.java
File metadata and controls
40 lines (33 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.securefileshare.servlets;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
import org.json.JSONObject;
public class CheckHashVerificationServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession(false);
JSONObject jsonResponse = new JSONObject();
if (session != null) {
String downloadedHash = (String) session.getAttribute("downloadedHash");
String expectedHash = (String) session.getAttribute("expectedHash");
String encryptedHash = (String) session.getAttribute("encryptedHash");
String fileName = (String) session.getAttribute("fileName");
String fileSize = (String) session.getAttribute("fileSize");
jsonResponse.put("success", true);
jsonResponse.put("downloadedHash", downloadedHash);
jsonResponse.put("expectedHash", expectedHash);
jsonResponse.put("encryptedHash", encryptedHash);
jsonResponse.put("fileName", fileName);
jsonResponse.put("fileSize", fileSize);
jsonResponse.put("match", downloadedHash != null && downloadedHash.equals(expectedHash));
} else {
jsonResponse.put("success", false);
jsonResponse.put("message", "No session found");
}
response.setContentType("application/json");
response.getWriter().write(jsonResponse.toString());
}
}