KEYCLOAK-12217 Use StandartCharsets in module "server-spi-private"

This commit is contained in:
Andrei Arlou 2019-11-23 22:31:46 +03:00 committed by Stian Thorgersen
parent 677349de6c
commit 198e2a989f
2 changed files with 6 additions and 18 deletions

View file

@ -17,7 +17,7 @@
package org.keycloak.crypto;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import org.keycloak.provider.Provider;
@ -28,12 +28,8 @@ public interface HashProvider extends Provider {
default byte[] hash(String input) throws HashException {
try {
byte[] inputBytes = input.getBytes("UTF-8");
return hash(inputBytes);
} catch (UnsupportedEncodingException e) {
throw new HashException("Unsupported encoding when trying to hash", e);
}
byte[] inputBytes = input.getBytes(StandardCharsets.UTF_8);
return hash(inputBytes);
}

View file

@ -19,7 +19,7 @@ package org.keycloak.models.utils;
import org.keycloak.common.util.Base64;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -45,16 +45,8 @@ public class SHAPasswordEncoder {
public String encode(String rawPassword) {
MessageDigest messageDigest = getMessageDigest();
String encodedPassword = null;
try {
byte[] digest = messageDigest.digest(rawPassword.getBytes("UTF-8"));
encodedPassword = Base64.encodeBytes(digest);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("Credential could not be encoded");
}
return encodedPassword;
byte[] digest = messageDigest.digest(rawPassword.getBytes(StandardCharsets.UTF_8));
return Base64.encodeBytes(digest);
}
public boolean verify(String rawPassword, String encodedPassword) {