diff --git a/impl/src/main/java/com/sun/faces/renderkit/ByteArrayGuard.java b/impl/src/main/java/com/sun/faces/renderkit/ByteArrayGuard.java index 4cd2e85902..c42a629223 100644 --- a/impl/src/main/java/com/sun/faces/renderkit/ByteArrayGuard.java +++ b/impl/src/main/java/com/sun/faces/renderkit/ByteArrayGuard.java @@ -34,6 +34,7 @@ import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; +import java.util.Base64; import javax.crypto.BadPaddingException; import javax.crypto.IllegalBlockSizeException; @@ -42,7 +43,6 @@ import javax.naming.InitialContext; import javax.naming.NamingException; import javax.servlet.http.HttpSession; -import javax.xml.bind.DatatypeConverter; /** *

This utility class is to provide both encryption and @@ -203,7 +203,7 @@ private void setupKeyAndMac() { try { InitialContext context = new InitialContext(); String encodedKeyArray = (String) context.lookup("java:comp/env/jsf/ClientSideSecretKey"); - byte[] keyArray = DatatypeConverter.parseBase64Binary(encodedKeyArray); + byte[] keyArray = Base64.getDecoder().decode(encodedKeyArray); sk = new SecretKeySpec(keyArray, KEY_ALGORITHM); } catch(NamingException exception) { diff --git a/impl/src/main/java/com/sun/faces/util/ByteArrayGuardAESCTR.java b/impl/src/main/java/com/sun/faces/util/ByteArrayGuardAESCTR.java index ac833f2fda..e7ced5a544 100644 --- a/impl/src/main/java/com/sun/faces/util/ByteArrayGuardAESCTR.java +++ b/impl/src/main/java/com/sun/faces/util/ByteArrayGuardAESCTR.java @@ -26,6 +26,7 @@ import javax.crypto.spec.IvParameterSpec; import javax.faces.FacesException; import java.security.SecureRandom; +import java.util.Base64; import java.util.SortedMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -35,7 +36,6 @@ import javax.crypto.spec.SecretKeySpec; import javax.naming.InitialContext; import javax.naming.NamingException; -import javax.xml.bind.DatatypeConverter; /** *

This utility class is to provide both encryption and @@ -104,7 +104,7 @@ public String encrypt(String value) { // encrypt the plaintext byte[] encdata = encryptCipher.doFinal(bytes); // Base64 encode the encrypted bytes - securedata = DatatypeConverter.printBase64Binary(encdata); + securedata = Base64.getEncoder().encodeToString(encdata); } catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, @@ -119,7 +119,7 @@ public String encrypt(String value) { public String decrypt(String value) throws InvalidKeyException { - byte[] bytes = DatatypeConverter.parseBase64Binary(value);; + byte[] bytes = Base64.getDecoder().decode(value); try { Cipher decryptCipher = Cipher.getInstance(CIPHER_CODE); @@ -146,7 +146,7 @@ private void setupKeyAndCharset() { InitialContext context = new InitialContext(); String encodedKeyArray = (String) context.lookup("java:comp/env/jsf/FlashSecretKey"); if (null != encodedKeyArray) { - byte[] keyArray = DatatypeConverter.parseBase64Binary(encodedKeyArray); + byte[] keyArray = Base64.getDecoder().decode(encodedKeyArray); if (keyArray.length < 16) { throw new FacesException("key must be at least 16 bytes long."); }