diff --git a/crypto/src/main/java/org/springframework/security/crypto/bcrypt/BCrypt.java b/crypto/src/main/java/org/springframework/security/crypto/bcrypt/BCrypt.java index f6c677057b..7ccaa91b9e 100644 --- a/crypto/src/main/java/org/springframework/security/crypto/bcrypt/BCrypt.java +++ b/crypto/src/main/java/org/springframework/security/crypto/bcrypt/BCrypt.java @@ -733,11 +733,7 @@ public class BCrypt { public static String hashpw(String password, String salt) { byte passwordb[]; - try { - passwordb = password.getBytes("UTF-8"); - } catch (UnsupportedEncodingException uee) { - throw new AssertionError("UTF-8 is not supported"); - } + passwordb = password.getBytes(StandardCharsets.UTF_8); return hashpw(passwordb, salt); } diff --git a/crypto/src/main/java/org/springframework/security/crypto/codec/Utf8.java b/crypto/src/main/java/org/springframework/security/crypto/codec/Utf8.java index 1fe58f33d2..a2274fa75d 100644 --- a/crypto/src/main/java/org/springframework/security/crypto/codec/Utf8.java +++ b/crypto/src/main/java/org/springframework/security/crypto/codec/Utf8.java @@ -19,6 +19,7 @@ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.CharacterCodingException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; /** * UTF-8 Charset encoder/decoder. @@ -28,7 +29,7 @@ import java.nio.charset.Charset; * @author Luke Taylor */ public final class Utf8 { - private static final Charset CHARSET = Charset.forName("UTF-8"); + private static final Charset CHARSET = StandardCharsets.UTF_8; /** * Get the bytes of the String in UTF-8 encoded form. diff --git a/test/src/main/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessors.java b/test/src/main/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessors.java index 2bef540d08..83324f7985 100644 --- a/test/src/main/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessors.java +++ b/test/src/main/java/org/springframework/security/test/web/servlet/request/SecurityMockMvcRequestPostProcessors.java @@ -18,6 +18,7 @@ package org.springframework.security.test.web.servlet.request; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.security.cert.CertificateException; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; @@ -638,12 +639,7 @@ public final class SecurityMockMvcRequestPostProcessors { } private static String md5Hex(String a2) { - try { - return DigestUtils.md5DigestAsHex(a2.getBytes("UTF-8")); - } - catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + return DigestUtils.md5DigestAsHex(a2.getBytes(StandardCharsets.UTF_8)); } } @@ -985,12 +981,7 @@ public final class SecurityMockMvcRequestPostProcessors { private HttpBasicRequestPostProcessor(String username, String password) { byte[] toEncode; - try { - toEncode = (username + ":" + password).getBytes("UTF-8"); - } - catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + toEncode = (username + ":" + password).getBytes(StandardCharsets.UTF_8); this.headerValue = "Basic " + new String(Base64.getEncoder().encode(toEncode)); }