-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashCriptografico.java
More file actions
51 lines (42 loc) · 1.71 KB
/
HashCriptografico.java
File metadata and controls
51 lines (42 loc) · 1.71 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
41
42
43
44
45
46
47
48
49
50
51
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Caroline Ignácio
*/
public class HashCriptografico extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String senha = request.getParameter("algorithm");
MessageDigest algorithm;
String senhahex = "";
try {
algorithm = MessageDigest.getInstance("SHA-256");
byte messageDigest[] = algorithm.digest(senha.getBytes("UTF-8"));
StringBuilder hexString = new StringBuilder();
for (byte b : messageDigest) {
hexString.append(String.format("%02X", 0xFF & b));
}
System.out.println(hexString.toString());
senhahex = hexString.toString();
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(HashCriptografico.class.getName()).log(Level.SEVERE, null, ex);
}
request.setAttribute("senhahex", senhahex);
request.getRequestDispatcher("HashCriptografico.jsp").forward(request, response);
}
}