main
Last change
on this file was 980eeda, checked in by Test <matonikolov77@…>, 2 years ago |
Restructuring project
|
-
Property mode
set to
100644
|
File size:
939 bytes
|
Line | |
---|
1 | package com.wediscussmovies.project.model;
|
---|
2 |
|
---|
3 |
|
---|
4 | import java.math.BigInteger;
|
---|
5 | import java.nio.charset.StandardCharsets;
|
---|
6 | import java.security.MessageDigest;
|
---|
7 | import java.security.NoSuchAlgorithmException;
|
---|
8 |
|
---|
9 | public class PasswordEncoder {
|
---|
10 | public static byte[] getSHA(String input) throws NoSuchAlgorithmException
|
---|
11 | {
|
---|
12 | MessageDigest md = MessageDigest.getInstance("SHA-512");
|
---|
13 |
|
---|
14 | return md.digest(input.getBytes(StandardCharsets.UTF_8));
|
---|
15 | }
|
---|
16 |
|
---|
17 | public static String toHexString(byte[] hash)
|
---|
18 | {
|
---|
19 | BigInteger number = new BigInteger(1, hash);
|
---|
20 |
|
---|
21 | StringBuilder hexString = new StringBuilder(number.toString(16));
|
---|
22 |
|
---|
23 | while (hexString.length() < 32)
|
---|
24 | {
|
---|
25 | hexString.insert(0, '0');
|
---|
26 | }
|
---|
27 |
|
---|
28 | return hexString.toString();
|
---|
29 | }
|
---|
30 |
|
---|
31 | public static String getEncodedPasswordString(String password) throws NoSuchAlgorithmException {
|
---|
32 | return toHexString(getSHA(password));
|
---|
33 | }
|
---|
34 |
|
---|
35 | }
|
---|
36 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.