-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
17 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
package access.config; | ||
|
||
import org.apache.commons.codec.digest.DigestUtils; | ||
import org.apache.commons.lang3.RandomStringUtils; | ||
|
||
import java.net.URLEncoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.SecureRandom; | ||
import java.util.Base64; | ||
import java.util.Random; | ||
|
||
public class HashGenerator { | ||
|
||
private static final Random secureRandom = new SecureRandom(); | ||
public static final DigestUtils digestUtils = new DigestUtils("SHA3-256"); | ||
|
||
private HashGenerator() { | ||
} | ||
|
||
public static String generateHash() { | ||
public static String generateRandomHash() { | ||
byte[] aesKey = new byte[128]; | ||
secureRandom.nextBytes(aesKey); | ||
String base64 = Base64.getEncoder().encodeToString(aesKey); | ||
return URLEncoder.encode(base64, StandardCharsets.UTF_8).replaceAll("%", ""); | ||
//Avoid decoding / encoding as URL parameter problems | ||
return Base64.getUrlEncoder().withoutPadding().encodeToString(aesKey); | ||
} | ||
|
||
public static String generateToken() { | ||
return RandomStringUtils.random(36, true, true); | ||
} | ||
|
||
public static String hashToken(String token) { | ||
return new DigestUtils("SHA3-256").digestAsHex(token); | ||
return digestUtils.digestAsHex(token); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters