Skip to content

Commit

Permalink
Removed JAXB dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Guillermo González de Agüero <z06.guillermo@gmail.com>
  • Loading branch information
ggam committed Sep 23, 2018
1 parent 7ddb874 commit c633e7a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,7 +43,6 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.http.HttpSession;
import javax.xml.bind.DatatypeConverter;

/**
* <p>This utility class is to provide both encryption and
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,7 +36,6 @@
import javax.crypto.spec.SecretKeySpec;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.xml.bind.DatatypeConverter;

/**
* <p>This utility class is to provide both encryption and
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand All @@ -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.");
}
Expand Down

0 comments on commit c633e7a

Please sign in to comment.