Лабораторная 2 на 5 готово

This commit is contained in:
Dmitry
2026-10-21 20:50:08 +03:00
parent 65003b6119
commit 5eb4db24a8
63 changed files with 2752 additions and 31 deletions
@@ -0,0 +1,28 @@
package org.example.config;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.HexFormat;
public final class TokenHasher {
private static final SecureRandom RANDOM = new SecureRandom();
public TokenHasher() {}
public static String newRawToken(){
byte[] bytes = new byte[32];
RANDOM.nextBytes(bytes);
return HexFormat.of().formatHex(bytes);
}
public static String sha256(String rawToken) {
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] dig = md.digest(rawToken.getBytes(StandardCharsets.UTF_8));
return HexFormat.of().formatHex(dig);
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}