solomax commented on a change in pull request #462:
URL: https://github.com/apache/wicket/pull/462#discussion_r592833393



##########
File path: 
wicket-util/src/main/java/org/apache/wicket/util/crypt/AbstractJceCrypt.java
##########
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.util.crypt;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.security.GeneralSecurityException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.AlgorithmParameterSpec;
+import java.util.Base64;
+import javax.crypto.Cipher;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+
+
+/**
+ * Base class for JCE based ICrypt implementations.
+ * 
+ */
+public abstract class AbstractJceCrypt implements ICrypt
+{
+       /** Encoding used to convert java String from and to byte[] */
+       public static final Charset CHARACTER_ENCODING = StandardCharsets.UTF_8;
+
+       /** Log. */
+       private static final Logger log = 
LoggerFactory.getLogger(AbstractJceCrypt.class);
+
+    protected Cipher buildCipher(int opMode, SecretKey secretKey, String 
transformation, AlgorithmParameterSpec params)
+    {
+        try 
+        {
+            Cipher crypter = Cipher.getInstance(transformation);
+            crypter.init(opMode, secretKey, params);
+            return crypter;
+        } catch (InvalidKeyException | InvalidAlgorithmParameterException 
+                | NoSuchAlgorithmException | NoSuchPaddingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
+        * Decrypts a string into a string.
+        * 
+        * @param text
+        *            text to decrypt
+        * @return the decrypted text
+        */
+       @Override
+       public final String decryptUrlSafe(final String text)
+       {
+               try
+               {
+                       byte[] decoded = 
java.util.Base64.getUrlDecoder().decode(text);
+                       return new String(decryptByteArray(decoded), 
CHARACTER_ENCODING);
+               }
+               catch (Exception ex)
+               {
+                       log.debug("Error decoding text: " + text, ex);

Review comment:
       `log.debug("Error decoding text: {}", text, ex);` will work as expected: 
will print message and trace :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to