mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Added SecretKeyGenerator class
This commit is contained in:
parent
9a73b7b7d1
commit
98402dd45b
@ -0,0 +1,27 @@
|
||||
package net.simon987.server.crypto;
|
||||
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
public class SecretKeyGenerator {
|
||||
|
||||
private static final String KEY_GENERATION_ALGORITHM = "HmacSHA1";
|
||||
private KeyGenerator keyGen;
|
||||
|
||||
public SecretKeyGenerator() {
|
||||
try {
|
||||
keyGen = KeyGenerator.getInstance(KEY_GENERATION_ALGORITHM);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException("Error creating Key generator", e);
|
||||
}
|
||||
keyGen.init(new SecureRandom(SecureRandom.getSeed(32)));
|
||||
}
|
||||
|
||||
public String generate() {
|
||||
SecretKey secretKey = keyGen.generateKey();
|
||||
return Base64.getEncoder().encodeToString(secretKey.getEncoded());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user